Looping / Changing Variables

rushdot

New member
Joined
Aug 29, 2009
Messages
2
Programming Experience
Beginner
Hi All,

Sorry if I've created this query in the wrong topic, but I sure this will be an easy one for the pros.

I fairly new to VB.net, I really just teaching myself, by looking for my answers on the net. However I cannot find the answer to this query:

I am using the following code to check whether a date(s) fall into a date range.

There are could be six dates BH1, BH2, etc

Dim BH1 As Date = XmlDoc2.SelectSingleNode("B/H1").InnerText()
Dim BH2 As Date = XmlDoc2.SelectSingleNode("B/H2").InnerText()
Dim BH3 As Date = XmlDoc2.SelectSingleNode("B/H3").InnerText()
Dim BH4 As Date = XmlDoc2.SelectSingleNode("B/H4").InnerText()
Dim BH5 As Date = XmlDoc2.SelectSingleNode("B/H5").InnerText()
Dim BH6 As Date = XmlDoc2.SelectSingleNode("B/H6").InnerText()


'Loop check each date
Dim d As Integer
For d = 1 To 6
Dim chkdateNUM As Integer = 1

'Check whether theres a bank on my date range
Dim CompareDates As New List(Of Date)




CompareDates.Add(StartDate)
CompareDates.Add(EndDate)
Dim chkdate As Date = BH1
CompareDates.Sort()

If chkdate >= CompareDates(0) And chkdate <= CompareDates(1) Then
MsgBox("YES")
ElseIf chkdate = Form4.DateTimePicker3.Value Then
MsgBox("YES 2")
Else
MsgBox("NO")
End If

Next d
Call SumTotal()

Catch ex As Exception

MsgBox(ex.Message)

End Try

I've created a loop, but how do I change the Dim chkdate As Date = BH1
so it checked each date?

Thanks for your help
 
Instead of putting the variables in 6 seperate variables put them in an array then loop through the array. That's the most conventional way of doing it.

DarrenK
 
Hi Darren,

Thanks, I really appreciate it.

It works great.

Dim myArray(0 To 1) As String

myArray(0) = "31/08/2009"
myArray(1) = "12/08/2010"


Dim itm As Object
For Each itm In myArray

then i run my bit of code.

Thanks again

Instead of putting the variables in 6 seperate variables put them in an array then loop through the array. That's the most conventional way of doing it.

DarrenK
 
Back
Top