943,518 Members | Top Members by Rank

Ad:
May 8th, 2003
0

Array

Expand Post »
I'm new with VB and I'm trying to write an array to find the time zone per state.


AL = CST
NY = EST
CA = PST

If I have a data that has NY as a state I will put EST on the output ...]

Can somebody sho me the basic of array writing.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ynnar777 is offline Offline
1 posts
since May 2003
May 9th, 2003
0
Re: Array
This is untested, but something like this might work

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. string timeZone[3], state, zone
  2. timeZone[0] = "CST"
  3. timeZone[1] = "EST"
  4. timeZone[2] = "PST"
  5.  
  6. if state="AL" then zone=timeZone[0]
  7. if state="NY" then zone=timeZone[1]
  8. if state="CA" then zone=timeZone[2]
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
May 10th, 2003
0
Re: Array
Close Dani :-), but this isn't C/Java :-P.

First of all, I'm assuming your using VB6. If you're not, tell me what VB version you're using and I'll adjust the code.

A better way of implimenting this, is to add a Class Module. I named my class module clsStateTime, and this is the code inside it:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public state As String
  2.  
  3. Public Function TimeZone() As String
  4. Select Case UCase(state)
  5. Case "NY"
  6. TimeZone = "EST"
  7. Case "NJ"
  8. TimeZone = "EST"
  9. Case Else
  10. TimeZone = "Unknown"
  11. End Select
  12. End Function

You should fill in the other 50 states with the results you want. To use this class, I made this code under a command button (but, you could do it however you want):

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. 'The index holds the amount of values you want to put in the array
  3. Dim stinfo(3) As New clsStateTime
  4. stinfo(0).state = "nj"
  5. stinfo(1).state = "ny"
  6. stinfo(2).state = "asdf"
  7. MsgBox (stinfo(0).TimeZone)
  8. MsgBox (stinfo(1).TimeZone)
  9. MsgBox (stinfo(2).TimeZone)
  10. End Sub

Just as a note, the index is the number in between the ()!

Dani, notice how I Dim'ed it with a (2), but I used 3 "slots" in the array? Thats another VB difference :-P. Oh yeah, we don't dim vars with the type first either :-P.
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: static compile
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: HELP WITH FTP, PLEASE:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC