Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

negative #s in database string 1

Status
Not open for further replies.

RickBooker

Technical User
Jan 26, 2000
17
US
To start with I am brand spanking new at programming of any kind.<br><br>I have written an application (after much cussing and gnashing of teeth) that creates an Access database from an ODBC datasource (Impact/Encore)I am pulling records from a .dat file into the Access database, everything works great UNTIL a negative number is read then the app crashes without writing any records at all to the table.<br><br>The Impact/Encore program inserts a &quot;p&quot; as the last character in the Runtimehours field section of the data string to indicate a negative number. The negatives are used to adjust incorrectly entered employee work hours. <br><br>My question is. What do I do to handle these negative &quot;p&quot; entries? Any ideas, help, nudge in the right direction would be greatly appreciated.<br>Thanks, Rick<br>
 
Rick,<br><br>Are you using VB or Access to write this?<br><br>If you're using VB - set the option in Tools/Options to break on any error and examine the Err and Error variables in the immediate window - should give you a starting point.<br><br>Access? Hmm - ask your question in the Access forum, I know as much about access as a pig knows about Sunday.<br><br>Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
I am creating a table in an Access database with my VB App.<br>Every thing works great until it reads the negative number indicated by &quot;p&quot; . The app stops when it reads the data in the Runtimehours field 000020p (this is negative 20 hours. The p denotes a negative in the datastring from original creating program (Encore)<br><br>How should I handle this record? I have tried an If statement trying to convert the p to - without success. The app still stops when reading the negative entry.<br><br>Any ideas would be greatly appreciated.<br>Thanks<br><br>partial code that adds the records to the Access table &quot;Eastern&quot;<br><br><br>&nbsp;If StartFlag Then<br>'<br>&nbsp;If Val(Mid(SourceStr3, ACOSPCPRecordtype, 2)) = 10 And<br>InStr(Mid(SourceStr3, ACOSPCPTrantype, 1), &quot;L&quot;) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>With rstEASTERN&nbsp;&nbsp;<br>.AddNew<br>.Fields(&quot;Job&quot;) = Mid(SourceStr3, 1, 8)<br>.Fields(&quot;Recordtype&quot;) = Mid(SourceStr3, ACOSPCPRecordtype,_ 2)<br>.Fields(&quot;Trantype&quot;) = Mid(SourceStr3, ACOSPCPTrantype, 1)<br>.Fields(&quot;RunTimehours&quot;) = Mid(SourceStr3,_ ACOSPCPRuntimehours, 7)<br>.Fields(&quot;Employee&quot;) = Mid(SourceStr3, ACOSPCPEmployee, 6)<br>.Fields(&quot;Hierarchy5&quot;) = Mid(SourceStr3, ACOSPCPHierarchy5,_ 3)<br><br>.Update<br>Counter = Counter + 1<br>
 
Rick,<br><br>Ok. You need to create a function in VB that takes either a string or a number (it mustn't care which) and returns a negative number if there's a 'p' (is it always a 'p'?) and a positive number otherwise.<br><br>Not bad for a first project - by the way<br><br>Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Thanks Mike,<br>I created a function to handle the negative numbers as well as decimals. Seems to work. Part of it is.......<br><br>Function IMPACTtoIEEEReal(SourceString As String, StartPtr As Integer, Length As Integer, Decimals As Byte) As Double<br>' Code<br>&nbsp;&nbsp;&nbsp;&nbsp;IMPACTtoIEEEReal = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;If Length = 0 Then Exit Function<br>&nbsp;&nbsp;&nbsp;&nbsp;Multiplicand = 1 * 10 ^ (Length - 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;For Ptr = 0 To Length - 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IMPACTtoIEEEReal = IMPACTtoIEEEReal + (CDbl(Val(Mid(SourceString, StartPtr + Ptr, 1))) * Multiplicand)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Multiplicand = Multiplicand / 10<br>&nbsp;&nbsp;&nbsp;&nbsp;Next<br>&nbsp;&nbsp;&nbsp;&nbsp;Select Case Asc(Mid(SourceString, StartPtr + (Length - 1), 1))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &H70<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IMPACTtoIEEEReal = IMPACTtoIEEEReal * -1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case &H71<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IMPACTtoIEEEReal = (IMPACTtoIEEEReal + 1) * -1<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top