Answer» I have a long script that sits in my richtextbox this line I want to change using a numeric up and down; the 1 id like to change to 1-24 It would be nice if it can remember the new value next time I open the program too I have no Idea how to do this, or even where to start. I have other lines id like to change in a similar fashion. please help.
" CurrentTaskInterval = hours_in_ms(1);", _More information will get you more and better answers. What version of Visual Basic? What OS are you using.?
My own preference is to break up things into smaller parts I can easily handle. You should be able to insert a REM ARK that will remind you of the need to edit an item often. Or just do like me and break it into pats.Ok, its Visual Basic 2010 Express
I think I need to express this line differently " CurrentTaskInterval = hours_in_ms(1);", _ since all I want to change is the 1 Although I'm not sure what I'm doing, I'm new to programming and and muddling along here. All it is, is a text EDITOR and the text just happens to be code, unrelated code.
The program I'm working on is this
Public Class Form1
Dim Lines() As String = { _ " // Some macros for defining time intervals in milliseconds", _ "#define seconds_in_ms(s) ((s)*1000UL)", _ "#define minutes_in_ms(m) ((m)*60UL*1000UL)", _ "#define hours_in_ms(h) ((h)*60UL*60UL*1000UL)", _ "#define days_in_ms(d) ((d)*24UL*60UL*60UL*1000UL)", _ "#define weeks_in_ms(w) ((w)*7UL*24UL*60UL*60UL*1000UL)", _ "", _ "unsigned long CycleStartTime = 0;", _ "unsigned long LastTaskTime = 0;", _ "unsigned long CurrentTaskInterval = 0;", _ "unsigned Task = 3; //All you had to change was this. 1st time, Task will = 3.", _ "", _ "", _ "void setup() {", _ "", _ "", _ " pinMode(2, OUTPUT); //PH down", _ " pinMode(3, OUTPUT); //B nutrient solution", _ " pinMode(4, OUTPUT); //A nutrient solution", _ " pinMode(5, OUTPUT); //Drain pump", _ " pinMode(6, OUTPUT); //Solenoid Valve", _ " pinMode(7, OUTPUT); //Nutrient Heater", _ " pinMode(8, OUTPUT); //Not used Future Nutrient/PH contoller", _ "", _ " digitalWrite(2, HIGH); //PH down off", _ " digitalWrite(3, HIGH); //B nutrient solution off", _ " digitalWrite(4, HIGH); //A nutrient solution off", _ " digitalWrite(5, HIGH); //Drain pump off", _ " digitalWrite(6, HIGH); //Solenoid Valve off", _ " digitalWrite(7, HIGH); //Nutrient Heater off", _ "}", _ "", _ "void loop() {", _ "", _ "", _ " unsigned long currentTime = millis();", _ "", _ " // If the time has not yet come to perform a task", _ " if (currentTime - LastTaskTime >= CurrentTaskInterval)", _ " LastTaskTime = currentTime;", _ "", _ " switch (Task)", _ " {", _ " case 0:", _ " CycleStartTime = currentTime; // Remember this time", _ "", _ " digitalWrite(5,LOW); // set the drain pump on flush", _ "", _ " CurrentTaskInterval = minutes_in_ms(16);", _ " break;", _ "", _ " case 1:", _ " digitalWrite(5,HIGH); // set the drain pump off flush", _ " digitalWrite(6,LOW); // set the Solenoid Valve on flush", _ " CurrentTaskInterval = hours_in_ms(1);", _ " break;", _ "", _ " case 2:", _ " digitalWrite(6,HIGH); // set the Solenoid Valve off flush", _ " digitalWrite(7,LOW); // set the Nutrient Heater on flush", _ " CurrentTaskInterval = minutes_in_ms(60);", _ " break;", _ "", _ " case 3:", _ " digitalWrite(5,LOW); // set the drain pump on", _ " digitalWrite(7,HIGH); // set the Nutrient Heater off", _ " CurrentTaskInterval = minutes_in_ms(16);", _ " break;", _ "", _ " case 4:", _ " digitalWrite(5,HIGH); // set the drain pump off", _ " digitalWrite(6,LOW); // set the Solenoid Valve on", _ " digitalWrite(2,LOW); // set the PH down on", _ " digitalWrite(3,LOW); // set the B nutrient solution on", _ " digitalWrite(4,LOW); // set the A nutrient solution on", _ " CurrentTaskInterval = seconds_in_ms(10);", _ " break;", _ "", _ "", _ "case 5:", _ " digitalWrite(2,HIGH); // set the PH down off", _ " digitalWrite(6,LOW); // set the Solenoid Valve on", _ " digitalWrite(3,LOW); // set the B nutrient solution on", _ " digitalWrite(4,LOW); // set the A nutrient solution on", _ " CurrentTaskInterval = minutes_in_ms(6);", _ "break;", _ "", _ "", _ "case 6:", _ "digitalWrite(3,HIGH); // set the B nutrient solution off", _ "digitalWrite(6,LOW); // set the Solenoid Valve on", _ "digitalWrite(4,LOW); // set the A nutrient solution on", _ " CurrentTaskInterval = minutes_in_ms(5.04);", _ "break;", _ "", _ "", _ "case 7:", _ "digitalWrite(4,HIGH); // set the A nutrient solution off", _ "digitalWrite(6,LOW); // set the Solenoid Valve on", _ " CurrentTaskInterval = minutes_in_ms(5);", _ "break;", _ "", _ "", _ "case 8:", _ "digitalWrite(6,HIGH); // set the Solenoid Valve off", _ "digitalWrite(7,LOW); // set the Nutrient Heater on", _ "digitalWrite(8,HIGH); // set the Future Nutrient/PH contoller off", _ "CurrentTaskInterval = days_in_ms(1);", _ "break;", _ "", _ "case 9:", _ "case 10:", _ "case 11:", _ "case 12:", _ "case 13:", _ "case 14:", _ "case 15:", _ "case 16:", _ "case 17:", _ "case 18:", _ "case 19:", _ "case 20:", _ "case 21:", _ "digitalWrite(6,LOW); // set the Solenoid Valve on/ top up", _ "CurrentTaskInterval = seconds_in_ms(20);", _ "digitalWrite(6,HIGH); // set the Solenoid Valve off/ top up", _ "CurrentTaskInterval = days_in_ms(1);", _ "break;", _ "", _ "case 22:", _ "// Start over again in one week from the START of the cycle", _ " LastTaskTime = CycleStartTime;", _ " CurrentTaskInterval = weeks_in_ms(1);", _ " Task = 0; //starts loop at case 0", _ " break;", _ " }", _ "}"} Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TheText.Lines = Lines End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveTheText.Click SaveIt.InitialDirectory = "C:\" SaveIt.FileName = "SAVE AS..." SaveIt.Filter = "ino Files Only (*.ino) | *.ino" SaveIt.ShowDialog() Dim W As New IO.StreamWriter(SaveIt.FileName) W.Write(TheText.Text) W.Close() End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged If RadioButton2.Checked = True Then TheText.Text = TheText.Text.Replace(" Task = 0; //starts loop at case 0", " Task = 3; //starts loop at case 3") Else TheText.Text = TheText.Text.Replace(" Task = 3; //starts loop at case 3", " Task = 0; //starts loop at case 0") End If
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
End Sub End Class OK If using a text editor to alter the value, and you want to change the 1 to a 2 in the fragment hours_in_ms(1) you could aask the text editor to find hours_in_ms(1) and replace with hours_in_ms(2) Then save the file. But just asking it to change (1) to (2) may not work. You have to search and replace a unique fragment in a text editor. Unless you REALLY do want to replace all matches.
That is all I can think of.Sure that makes sense tell it to replace the hours_in_ms(1) but I want to save it too so when I replace the hours_in_ms(1) with a hours_in_ms(5) next time it starts with hours_in_ms(5)Now I think what you are doing is becoming more clear. It would seem that you really are new to common practice using in program design and maintenance. Sorry, don't MEAN to be arrogant.
Sometimes it is necessary no compile a program again to m sake it do a new thing you want. But sometimes you want it to do it the old way instead.
Quote " CurrentTaskInterval = hours_in_ms(1);", _
Appears to be a value that has a value at the start of the program. The name suggests that it will change, but it must start at 1. But you would like it to sometimes start at 2? Maybe what you want is a way to tell the program to start will a different value if you want.
Sorry, I don't have enough experience with Visual Basic to make a useful recommendation. It would seem that what you want is a command line option for the program at run time.
http://www.vbexplorer.com/VBExplorer/vb_feature/august2000/command_line_arguments.asp
If this has any relevance to what you want, please say so. Or try again to explain what you need in a general way. Maye BC will see this.
|