Results 1 to 7 of 7

Thread: [Newbie Question] Loop Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    3

    [Newbie Question] Loop Problem

    I am developing a GUI for a device called LabJack to get streaming data of UV light intensity.

    Code:
    For i = 0 To numScansToDisplay - 1
    
             For j = 1 To numChannel
    
        
    
            testdata = Format(adblData(j - 1 + (numChannel * i)), "#.####") + ","
    
            data = data + testdata
    
            
    
             Next j
    
            
    
             data = CStr(TimeValue(Now)) + data + vbCrLf
    
    
    
            Next i
    
              RichTextBox1.Text = RichTextBox1.Text + data
    This is the result i get

    4:31:41 PM4:31:41 PM4:31:41 PM4:31:41 PM-.0005,4.9894,-.3128,-.3178,

    -.0005,4.9843,-.3758,-.3909,

    -.0005,4.9843,-.411,-.4211,

    -.0005,4.9843,-.401,-.4236,

    4:31:42 PM4:31:42 PM4:31:42 PM4:31:42 PM.002,4.9843,-.3959,-.4262,

    -.0005,4.9818,-.4236,-.4362,

    -.0005,4.9818,-.3959,-.4262,

    .002,4.9793,-.4236,-.4312,



    But if i change the code to
    Code:
    data = data + CStr(TimeValue(Now)) + vbCrLf
    The results are

    -.0005,4.9894,-.3128,-.3178,4:31:41 PM

    -.0005,4.9843,-.3758,-.3909,4:31:41 PM

    -.0005,4.9843,-.411,-.4211,4:31:41 PM

    -.0005,4.9843,-.401,-.4236,4:31:41 PM

    In fact, what i am trying to get is:

    4:31:41 PM,.002,4.9843,-.3959,-.4262,

    4:31:41 PM,-.0005,4.9818,-.4236,-.4362,

    4:31:41 PM,-.0005,4.9818,-.3959,-.4262,

    4:31:41 PM,.002,4.9793,-.4236,-.4312,

    I have tried numeours codes but i have no idea how to do it
    Thanks for help

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [Newbie Question] Loop Problem

    With strings: Use & to combine them, not +

    If using math on strings, ensure you convert the string to appropriate variable type first, i.e., CDbl(theString), CLng(theString), etc. Failing to do this could result in type mismatch errors and/or potentially incorrect calculations.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: [Newbie Question] Loop Problem

    Try:

    data = CStr(TimeValue(Now)) & "," & data & "," & vbCrLf
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [Newbie Question] Loop Problem

    Quote Originally Posted by some1uk03 View Post
    Try:

    data = CStr(TimeValue(Now)) & "," & data & "," & vbCrLf
    But that isn't the only line that is using + to concatenate strings. OP should review post #2 also.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    3

    Re: [Newbie Question] Loop Problem

    Thanks LaVolpe and Some1uk30.

    I have tried your suggestions, but it doesn't work also.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Newbie Question] Loop Problem

    Since I cannot test your code, Try this and tell me what are the two exact messages that you are getting?

    Code:
    For i = 0 To numScansToDisplay - 1
        For j = 1 To numChannel
            testdata = Format(adblData(j - 1 + (numChannel * i)), "#.####") + ","
            Data = Data & testdata
        Next j
        
        MsgBox "1~~> " & Data '<~~ 1st Message
        
        Data = CStr(TimeValue(Now)) & Data & vbCrLf
        
        MsgBox "2~~> " & Data '<~~ 2nd Message
        
        Exit Sub '<~~ For testing purpose only
    Next i
    Last edited by Siddharth Rout; Feb 9th, 2010 at 05:37 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [Newbie Question] Loop Problem

    Quote Originally Posted by syahzuan View Post
    Thanks LaVolpe and Some1uk30.

    I have tried your suggestions, but it doesn't work also.
    Maybe you should show us your modified code and also tell us how you declared Data & testData.
    Last edited by LaVolpe; Feb 9th, 2010 at 09:31 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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