Explain VB Array

  • Thread starter Thread starter jrpisci
  • Start date Start date
J

jrpisci

Can someone explain to me what this code is doing? I have worked with
arrays in C++ but not VB. I don't know the VB code meanings.... A line
by line woud be very helpful.....

thanks

Dim BrassTag1 As String
Dim BrassTag2 As String
Dim LoadData1 As String
Dim LoadData2 As String
Dim LoadData3 As String
Dim LoadData4 As String
Dim loadnum() As String

Dim m_stLoadNumber As String

m_stLoadNumber = "BT540861_20060428043148"


'take the BT off the loadnumber
loadnum = Split(m_stLoadNumber, "BT")

'break up loadnumber into brasstag and load date
loadnum = Split(loadnum(1), "_")

'break the brasstag into 2 parts
BrassTag1 = Left(Format(loadnum(0), "000000"), 3)
BrassTag2 = Right(loadnum(0), 3)

'break up the load date into 4 parts
LoadData1 = Left(loadnum(1), 4)
LoadData2 = Mid(loadnum(1), 5, 4)
LoadData3 = Mid(loadnum(1), 9, 4)
LoadData4 = Right(loadnum(1), 2)
 
This code uses the Split function several times. The Split function creates
an arrray of strings. It breaks the string in the first argument into
elements based on the split character(s) in the second argument. The split
characters are not included in the output. For example:
x = "ABCD~EFGHRQ~E4H$Z"
z= Split(x, "~") will create a 3 element array.
z(0) = "ABCD"
z(1) = "EFGHRQ"
z(2) = "E4H$Z"

'Dimensions the following variables as string variables
Dim BrassTag1 As String
Dim BrassTag2 As String
Dim LoadData1 As String
Dim LoadData2 As String
Dim LoadData3 As String
Dim LoadData4 As String
'Dimensions an array of strings with no specified number of elements
Dim loadnum() As String

Dim m_stLoadNumber As String

'Populates the varialbe with a value
m_stLoadNumber = "BT540861_20060428043148"

'Creates a 2 element array. loadnum(0) will be a zero length string and
'loadnum(1) will contrain "540861_20060428043148"
'take the BT off the loadnumber
loadnum = Split(m_stLoadNumber, "BT")

'Recreate loadnum as a 2 element arrray
loadnum(0) = "540861"
loadnum(1) = "20060428043148"
'break up loadnumber into brasstag and load date
loadnum = Split(loadnum(1), "_")

'break the brasstag into 2 parts
'Put the left 3 characters of loandnum(0) in the variable BrasssTag1. The
formatting, in this case in unnecessary unless this value will sometimes not
be 6 characters in length.
BrassTag1 = "540"
BrassTag1 = Left(Format(loadnum(0), "000000"), 3)

'Put the right 3 characters of loadnum(0) in the variable BrassTag2
BrassTag2 = Right(loadnum(0), 3)

'break up the load date into 4 parts
'Put the left 4 characters from loadnum(1) into LoadData1
LoadData1 = Left(loadnum(1), 4)
'Put characters 5 through 8 from loadnum(1) into LoadData2
LoadData2 = Mid(loadnum(1), 5, 4)
'Put characters 9 through 12 from loadnum(1) into LoadData3
LoadData3 = Mid(loadnum(1), 9, 4)
'Put the right 2 characters from loadnum(1) into LoadData4
LoadData4 = Right(loadnum(1), 2)
 
Thank you. That does it.....

This code uses the Split function several times. The Split function creates
an arrray of strings. It breaks the string in the first argument into
elements based on the split character(s) in the second argument. The split
characters are not included in the output. For example:
x = "ABCD~EFGHRQ~E4H$Z"
z= Split(x, "~") will create a 3 element array.
z(0) = "ABCD"
z(1) = "EFGHRQ"
z(2) = "E4H$Z"

'Dimensions the following variables as string variables
Dim BrassTag1 As String
Dim BrassTag2 As String
Dim LoadData1 As String
Dim LoadData2 As String
Dim LoadData3 As String
Dim LoadData4 As String
'Dimensions an array of strings with no specified number of elements
Dim loadnum() As String

Dim m_stLoadNumber As String

'Populates the varialbe with a value
m_stLoadNumber = "BT540861_20060428043148"

'Creates a 2 element array. loadnum(0) will be a zero length string and
'loadnum(1) will contrain "540861_20060428043148"
'take the BT off the loadnumber
loadnum = Split(m_stLoadNumber, "BT")

'Recreate loadnum as a 2 element arrray
loadnum(0) = "540861"
loadnum(1) = "20060428043148"
'break up loadnumber into brasstag and load date
loadnum = Split(loadnum(1), "_")

'break the brasstag into 2 parts
'Put the left 3 characters of loandnum(0) in the variable BrasssTag1. The
formatting, in this case in unnecessary unless this value will sometimes not
be 6 characters in length.
BrassTag1 = "540"
BrassTag1 = Left(Format(loadnum(0), "000000"), 3)

'Put the right 3 characters of loadnum(0) in the variable BrassTag2
BrassTag2 = Right(loadnum(0), 3)

'break up the load date into 4 parts
'Put the left 4 characters from loadnum(1) into LoadData1
LoadData1 = Left(loadnum(1), 4)
'Put characters 5 through 8 from loadnum(1) into LoadData2
LoadData2 = Mid(loadnum(1), 5, 4)
'Put characters 9 through 12 from loadnum(1) into LoadData3
LoadData3 = Mid(loadnum(1), 9, 4)
'Put the right 2 characters from loadnum(1) into LoadData4
LoadData4 = Right(loadnum(1), 2)
 
Back
Top