|
-
Nov 8th, 2008, 03:07 AM
#1
Thread Starter
Fanatic Member
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
-
Nov 8th, 2008, 03:34 AM
#2
Member
Re: Skipping in for loop
make a condetion to proccess ur case and if the condetion is false try using exit for or goto:
-
Nov 8th, 2008, 04:25 AM
#3
Re: Skipping in for loop
You could set a condition inside the loop, using INSTR function to determine the existence of '/' in the data....
-
Nov 8th, 2008, 04:59 AM
#4
Thread Starter
Fanatic Member
Re: Skipping in for loop
 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
-
Nov 8th, 2008, 05:26 AM
#5
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...
-
Nov 8th, 2008, 07:46 AM
#6
Thread Starter
Fanatic Member
Re: Skipping in for loop
 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 .
-
Nov 8th, 2008, 07:52 AM
#7
Re: Skipping in for loop
That was just for demo purposes, of course you have to modify it to suit your needs...
-
Nov 8th, 2008, 07:57 AM
#8
Thread Starter
Fanatic Member
Re: Skipping in for loop
 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
-
Nov 8th, 2008, 08:13 AM
#9
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.
-
Nov 8th, 2008, 10:30 AM
#10
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
-
Nov 8th, 2008, 10:59 AM
#11
Fanatic Member
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
Alpha Micro: Alpha Basic, AS400 V5r2, EDI (Trusted Link/ Inovis.com),Access AS/400 via VB6, Qbasic for data conversions. A mix of Hardware too. ASCII Table , New Number to Words/66 digits , AS/400(v5r2) VB6 Viewer/Ask for code(ODBC) ^ What Is Transferring? , Check your Ports #Perfect Passwords , *Slide Bar Example , Logoff, Restart, Shut-Down PC *Keep Form On Top , Opaque Form ^ Create Objects at Run Time @ Check Key Caps Locks # GetTickCount(System Up Time) * Convert text to Excel & Collected Icons + Resize: Form/Text box ^ PC GateWay via Shell $ Drag & Drop Game ! PopUpMenu *Print File/no Open# Timer on Mult Forms ~ Splash & Mult Forms & Lots of Comments + Random/Timer/Guess * Dec >Hex >Oct >Bin % Get MAC (NIC) < saving to Registry > Wookiee Cookies \ BackUpDisk / World Conection SpeedTest $ Glossary Commonly Used Terms # phonetic list @ Detailed Computer Scan
When posting Code, Use tags.. [CODE] *Your Code* [/CODE]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|