Results 1 to 11 of 11

Thread: Skipping in for loop

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Skipping in for loop

    My recordset contains datas as 11/2, 8/3 , 7 ,9

    I am using FOR loop

    I used coding in loop to convert them to decimals. But, what i want now is if there are no fractions in the recordset the data alone must be skipped.

    (ie) it must convert to decimals for 11/2 and 8/3 but want to skip 7 and 9

    Pls do anyone help me in this coding

  2. #2
    Member
    Join Date
    Jul 2004
    Posts
    46

    Re: Skipping in for loop

    make a condetion to proccess ur case and if the condetion is false try using exit for or goto:
    haker7_8

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Skipping in for loop

    You could set a condition inside the loop, using INSTR function to determine the existence of '/' in the data....
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Skipping in for loop

    Quote Originally Posted by dee-u
    You could set a condition inside the loop, using INSTR function to determine the existence of '/' in the data....
    I used the coding Below but not working.


    Private Sub Command1_Click()
    rs.Open "check1", db, 3, 2
    If InStr(no1, "/") > 0 Then
    a = Left([no1], InStr([no1], "/") - 1)
    b = Right([no1], Len([no1]) - InStr([no1], "/"))
    c = a / b
    Call calc
    Else
    no1 = no1 / 1
    Call calc
    End If
    rs.Close
    End Sub

    Private Sub Form_Load()
    db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Bharani\Desktop\New Folder (2)\check.mdb;Persist Security Info=False"
    End Sub

    Private Sub calc()
    rs.Open "check2", 3, 2
    rs.AddNew
    rs.Fields(0) = no1
    rs.Update
    rs.Close
    End Sub

    My output needs to be 5.5, 2.67, 7, 9
    which must be added to database

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Skipping in for loop

    For parsing a fraction it may be easier to use a split...

    Code:
        Dim data() As String
        Dim firstValue As Long
        Dim secondValue As Long
        
        data = Split("100/50", "/")
        firstValue = data(0)
        secondValue = data(1)
        MsgBox firstValue / secondValue
    There is no code the save the record yet, you have to include it also if you want to save...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Skipping in for loop

    Quote Originally Posted by dee-u
    For parsing a fraction it may be easier to use a split...

    Code:
        Dim data() As String
        Dim firstValue As Long
        Dim secondValue As Long
        
        data = Split("100/50", "/")
        firstValue = data(0)
        secondValue = data(1)
        MsgBox firstValue / secondValue
    There is no code the save the record yet, you have to include it also if you want to save...

    I used your coding as this
    but not working

    Private Sub Command1_Click()
    rs.Open "check1", db, 3, 2
    Dim data() As String
    Dim firstValue As Long
    Dim secondValue As Long

    data = Split("100/50", "/")
    firstValue = data(0)
    secondValue = data(1)
    MsgBox firstValue / secondValue
    End Sub
    It only dividing the values which is 100/50 = 2, but i want my recorset values to be divided .

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Skipping in for loop

    That was just for demo purposes, of course you have to modify it to suit your needs...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Skipping in for loop

    Quote Originally Posted by dee-u
    That was just for demo purposes, of course you have to modify it to suit your needs...

    Ya But Instead of that 11/2 i specified my recordset field name as no1, but it is showin error as type missmatch

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Skipping in for loop

    You have to replace
    Code:
    data = Split("100/50", "/")
    with your own data...
    Last edited by dee-u; Nov 8th, 2008 at 08:17 AM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  10. #10
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Skipping in for loop

    Why not get only that data in recordset which you need to work on by altering your query. This way your program will be faster.


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  11. #11
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Skipping in for loop

    Code:
    Private Sub Command1_Click()
    rs.Open "check1", db, 3, 2
    If InStr(no1, "/") > 0 Then
         a = Left([no1], InStr([no1], "/") - 1)
         b = Right([no1], Len([no1]) - InStr([no1], "/"))
         c = a / b
         Call calc
      Else
         ' no1 = no1 / 1
         Call calc
      End If
     rs.Close
     End Sub
    ---
    Maybe I don't understand, if there is a '/'...you divide, if not...just write the number out

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