We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,703 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Array

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.

3
Contributors
2
Replies
2 Days
Discussion Span
10 Years Ago
Last Updated
4
Views
Related Article: passing arrays in visual basic is a Visual Basic 4 / 5 / 6 discussion thread by Chas Griff that has 1 reply and was last updated 9 years ago.
ynnar777
Newbie Poster
1 post since May 2003
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This is untested, but something like this might work

string timeZone[3], state, zone
timeZone[0] = "CST"
timeZone[1] = "EST"
timeZone[2] = "PST"

if state="AL" then zone=timeZone[0]
if state="NY" then zone=timeZone[1]
if state="CA" then zone=timeZone[2]
Dani
The Queen of DaniWeb
Administrator
21,564 posts since Feb 2002
Reputation Points: 1,555
Solved Threads: 376
Skill Endorsements: 124

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:

Public state As String

Public Function TimeZone() As String
    Select Case UCase(state)
        Case "NY"
            TimeZone = "EST"
        Case "NJ"
            TimeZone = "EST"
        Case Else
            TimeZone = "Unknown"
    End Select
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):

Private Sub Command1_Click()
    'The index holds the amount of values you want to put in the array
    Dim stinfo(3) As New clsStateTime
    stinfo(0).state = "nj"
    stinfo(1).state = "ny"
    stinfo(2).state = "asdf"
    MsgBox (stinfo(0).TimeZone)
    MsgBox (stinfo(1).TimeZone)
    MsgBox (stinfo(2).TimeZone)
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.

Tekmaven
Software Architect
Team Colleague
1,278 posts since Feb 2002
Reputation Points: 322
Solved Threads: 28
Skill Endorsements: 19

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0665 seconds using 2.47MB