1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Web;
using System.Net;
namespace CS_Ex1
{
public partial class Form1 : Form
{
private string tb1, tb2;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Connect_Click(object sender, EventArgs e)
{
WSMBT.Result Result;
wsmbtControl1.Mode = WSMBT.Mode.TCP_IP;
wsmbtControl1.ResponseTimeout = 1000;
Result = wsmbtControl1.Connect("127.0.0.1", 502);
if (Result != WSMBT.Result.SUCCESS)
MessageBox.Show(wsmbtControl1.GetLastErrorString());
}
private void Disconnect_Click_1(object sender, EventArgs e)
{
wsmbtControl1.Close();
}
private void button1_Click(object sender, EventArgs e)
{
Int16[] Registers = new Int16[20];
WSMBT.Result Result;
Result = wsmbtControl1.ReadHoldingRegisters(1, 0, 20, Registers);
if (Result == WSMBT.Result.SUCCESS)
{
string DataString = "";
string str = "";
for (int i = 0; i < 20; i++)
{
str = string.Format("{0:D}", Registers[0]);
str = string.Format("{0:D}", Registers[1]);
DataString = DataString + str + "\r\n";
}
TextBox1.Text = Registers[0].ToString();
TextBox2.Text = Registers[1].ToString();
tb1 = TextBox1.Text.ToString();
tb2 = TextBox2.Text.ToString();
}
else
{
MessageBox.Show(wsmbtControl1.GetLastErrorString());
}
}
private void Write_Click(object sender, EventArgs e)
{
Int16[] Registers = new Int16[20];
WSMBT.Result Result;
for (Int16 i = 0; i < 20; i++)
Registers[i] = i;
Result = wsmbtControl1.WriteMultipleRegisters(1, 0, 20, Registers);
if (Result != WSMBT.Result.SUCCESS)
{
MessageBox.Show(wsmbtControl1.GetLastErrorString());
}
}
public static void message_Click()
{
string senderusername = "XXX";
string senderpassword = "XXXX";
string senderid = "22687";
string sURL;
StreamReader objReader;
sURL = "URL";
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sURL);
try
{
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
objReader = new StreamReader(objStream);
objReader.Close();
}
catch (Exception ex)
{
ex.ToString();
}
}
}
}
在這個code變量TB1越來越改變所有我想要調用,將發送短信到用戶手機message_click()方法的時候,TB1值被改變或假設的方法其值爲10,然後tb1值更改爲68,那麼它應該調用message_click()併發送短消息我怎麼能調用時變量值的變化
u能請把它放在代碼中,我嘗試這一點,但沒有一樣是到目前爲止,我也許會犯錯的地方 –
@我犯了一個錯誤R-T!您需要將此行'tb1 = value;'更改爲'_tb1 = value;'否則您將得到一個StackOverflow異常。我在我的帖子中糾正了它。現在它可以工作。我測試了它 –
@ R-T在使它工作仍然沒有運氣? –