+ Reply to Thread
Results 1 to 4 of 4

How to loop with a String Variable

Hybrid View

  1. #1
    Registered User
    Join Date
    06-19-2007
    Posts
    6

    Expert Needed: How to loop Need Help With String Variable

    Expert Needed: How do you in a loop or with an array go from

    
        Dim Variable1 As String
        Call ibrd(udDevice, Variable1)
        Dim VariableDbl1 As Double
        VariableDbl1 = CDbl(Variable1)
        
        'display response in appropriate cell
        Worksheets("Temp1").Range("F53").value = VariableDbl1
    to this, without copying and pasting and changing variable1..2..3.4..5
    
        Dim Variable2 As String
        Call ibrd(udDevice, Variable2)
        Dim VariableDbl2 As Double
        VariableDbl2= CDbl(Variable2)
        
        'display response in appropriate cell
        Worksheets("Temp1").Range("F54").value = VariableDbl2
    I am trying to create a loop or an array which instead of copying and paste the bottom line and code and making Variable1 to Variable 2 and VariableDbl1 to VariableDbl2. The thing which I was having a problem was is how to increment a String or make a variable with an incremented value after it. Any thoughts?

    I had to do Dim Variable1 as String, then convert it to double afterwards, because or else it would give me a Compile error: ByRef argument type mismatch.
    Instead of making a 5 of these:

    Thanks in advanced
    Last edited by game; 06-19-2007 at 03:00 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    What does ibrd do? Where do the variables get assigned? What gets assigned to the variables? What determines the output positions?

    Perhaps a sample file showing more detail and some sample data with the expected output would clarify...


    rylo

  3. #3
    Registered User
    Join Date
    06-19-2007
    Posts
    6

    Error

    Sorry about the confusion. What I need help with are arrays. It doesn't seem to work.

    Dim Variable2 As String
    Dim Variable1(5) As String
    
    For i = 1 to 5 Step 1
    
    Variable1(i) = CDble(Variable2)
    
    Next i
    Gives me an Run-time error '13' Type Mismatch
    Any help
    Thanks

    The other functions such as ibwrt go to a different module which is from national instruments template on reading and writing from their serial port. It gets the value and puts it in Call ibrd(udDevice, ValuetobeStored) here labeled as Variable2. I am trying to make a for loop to read this value 5 times.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Your types are mismatched. Removing the CDbl will fix that.
    Dim Variable2 As String
    Dim Variable1(5) As String
    
    For i = 1 to 5 Step 1
    
    Variable1(i) = CDbl(Variable2)
    
    Next i

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1