Results 1 to 6 of 6

Thread: Simple Question, combine a string + int. Seperate with a ; ...& then write to LstBox

  1. #1

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Simple Question, combine a string + int. Seperate with a ; ...& then write to LstBox

    Ok so in one of my programs functions, I collect a STRING & an Integer (in two seperate variables), one after the other. Then do something with both of those.

    What I want to do is.....after getting the String lets call it NAME and the string = JENNIFER. Then I want to take the Integer I have just collected lets call it NUMBER and the integer = 100001.

    I want to combine NAME & NUMBER, add a delimiter ...in this case a " ; " symbol. Then add it to my listbox. Later I will save it to a text file (already have the code to do that)

    So my list box should look like this, 1 line each.....after combining NAME & NUMBER

    JENNIFER;100001
    SANDRA;20222
    DAVID;3033
    ALEX;333
    MICHELLE;8088888

    So how do i combine both a string & an integer...while separating it with a ; ?
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Simple Question, combine a string + int. Seperate with a ; ...& then write to Lst

    Dim s As String = name & ";" & number.ToString

    Or is there some deep subtlety that I'm missing here?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Simple Question, combine a string + int. Seperate with a ; ...& then write to Lst

    How can I make this one line?

    VB Code:
    Code:
    If Combo1.ListIndex = 3 Then
    RTFText2.LoadFile "FoxesWholeBook.rtf"
    BookLabel.Caption = "Foxe's Book of Martyrs"
    End If
    like this?

    Code:
    If Combo1.ListIndex = 3 Then RTFText2.LoadFile "FoxesWholeBook.rtf" BookLabel.Caption = "Foxe's Book of Martyrs" End If
    & ";" & does not work on this code.
    Thanks,
    GARY

  4. #4
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Simple Question, combine a string + int. Seperate with a ; ...& then write to Lst

    Code:
    If Combo1.ListIndex = 3 Then RTFText2.LoadFile "FoxesWholeBook.rtf" : BookLabel.Caption = "Foxe's Book of Martyrs"
    I'd recommend keeping the multi-line if statement blocks and perhaps properly indenting.
    Code:
    If Combo1.ListIndex = 3 Then 'load Foxe's book
    	RTFText2.LoadFile "FoxesWholeBook.rtf"
    	BookLabel.Caption = "Foxe's Book of Martyrs"
    End If
    Which is easier to debug? Which makes a problem more identifiable?

  5. #5
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Re: Simple Question, combine a string + int. Seperate with a ; ...& then write to Lst

    Thanks Zach,

    The code worked fine. I'm not concerned about bugs in this part of my code. This one line thing saved me a lot of work in listing a bunch of books. I used MS Excel to list all my books in one column and I broke the other code up into other columns, then I cut and pasted the whole thing and deleted the extra spaces. saved a lot of time. Thanks again. I didn't realize that I didn't need to use the "End If" statement in this code. Ah-Ha! Maybe other folks will learn from this post too.
    Thanks,
    GARY

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Simple Question, combine a string + int. Seperate with a ; ...& then write to Lst

    It's a very rare thing that it's a good idea to use a colon ( to concatenate lines of VB code and this is definitely not such a case. Never try to reduce the number of lines in your code simply to reduce the number of lines. The goal should always be to write code that is as readable as possible. There are rare occasions that using a colon helps in that regard but there's no way known that it does in this case. It makes the code harder to read and is therefore bad.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width