Reply

Join Date: May 2003
Posts: 1
Reputation: ynnar777 is an unknown quantity at this point 
Solved Threads: 0
ynnar777 ynnar777 is offline Offline
Newbie Poster

Array

 
0
  #1
May 8th, 2003
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,035
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb
 
0
  #2
May 9th, 2003
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]
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 898
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Solved Threads: 28
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend
 
0
  #3
May 10th, 2003
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.
-Ryan Hoffman

.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC