Results 1 to 11 of 11

Thread: Skipping in for loop

Hybrid View

  1. #1

    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

  2. #2
    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

  3. #3

    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 .

  4. #4
    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

  5. #5

    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

  6. #6
    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

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