Visual Basic people - question

Discussion in 'OT Technology' started by Joe_Cool, Oct 2, 2005.

  1. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    I'm starting to learn VB and I have a couple really simple noob questions:

    How do I pass data between forms? I'm writing a periodic table just for kicks and for practice, and when you click an element in the table, I want it to pop up another form with info about the element. All my elements are a single array of labels, and I need it to pass the index of the label you clicked to the new form, which will then pull up the data and display it.

    How do I make and access a global variable, and what is a better way to pass data from form1 to form2?

    My other question: How do you insert a line break into a label's caption?
    I don't want my label to look like this.

    Instead, I
    want it
    to look
    like this.

    How?
     
  2. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    Another question:

    Back in old-school basic, there used to be a pair of keywords Read and Data that worked like this:

    dim a$(10)
    for a = 1 to 10
    read a$(a)
    next

    Then near the end of the program, you'd have something like this:

    data "adam", "bob", "charlie", "doug", "eric", "fred", "george","howard","ike","joe"

    So that each "read" reads the next "data" item and moves the pointer one spot forward, and the net result was that the array was populated where a$(1) = "adam" and a$(10) = "joe".

    I see online that read and data aren't keywords anymore, and I'm curious whether there's any similar functionality. Otherwise, what's a convenient way to populate an array with arbitrary data (other than reading it in from a file, which will be what I eventually do, but not yet)?
     
  3. thewise1

    thewise1 Guest

    does

    label1.text = "I want it " & vbcrlf & "to look like" & vbcrlf & "this"

    work? :dunno:
     
  4. thewise1

    thewise1 Guest

    as for passing data between forms, just create a property in the class for the other form, and set the property of the new form before you show it.

    Dim newform as classname

    newform.property1 = whatever

    newform.show()
     
  5. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    :eek3: It does! Thanks.

    Now, is there a way to do that in my Label1 property sheet, so that I don't have to have 118 lines of code setting label text? :mamoru:

    What I'm after is for each element square to have the 1 or 2 letter symbol above the atomic number.
     
  6. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    That's what I ended up doing. I was hoping I could just share a variable, but I guess there's really no need for that, is there? :hs:
     
  7. thewise1

    thewise1 Guest

    add each label to a control collection, and for each label in the control collection, set the label to whatever you want :o

    I don't know how to do it through the IDE :o
     
  8. thewise1

    thewise1 Guest

    really it's the same thing :hs:
     
  9. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    I suppose so.

    I'm kind of embarrassed to admit it, but I actually kind of like VB. :o

    I can tell it's going to bring back all my bad programming habits from my BASIC days though. It took me a long time to unlearn them. :mamoru: Every language should have c-style syntax.
     
  10. lowfat

    lowfat 24/Mac/SciFi/PC Crew OT Supporter

    Joined:
    Oct 27, 2003
    Messages:
    63,949
    Likes Received:
    0
    Location:
    Grande Prairie, AB, Can
    I would just save the info to the registry :hs: then read it back from the registry.
     
  11. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    I don't know how to do that yet. :o
     
  12. Spectracide

    Spectracide Active Member

    Joined:
    Sep 23, 2002
    Messages:
    2,982
    Likes Received:
    0
    Share variables between forms? Easy.
    Project -> Add Module

    Inside the module declare a variable like this:
    Global [variable] As [type]

    And then you should be able to set it and use it between forms...
     
  13. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,388
    Likes Received:
    581
    Sweet. That's what I was looking for. I have a big array read in from a file that needs to be accessible from pretty much everywhere. :bigthumb:
     

Share This Page