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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can some one help with this VBA formula to Crystal

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Public Function I25(Numbers)
' Copyright BarcodeONE Corporation 10/7/2001

Dim BinaryNum
Dim BinArray(50) As String
Dim Numbers1, num2 As String
Dim a, b As Integer
Dim ConvertedNum As String

If Len(Numbers) Mod 2 Then
'Odd number, add leading zero
Numbers1 = "0" & Numbers
Else
'WE have an even number of characters
Numbers1 = Numbers
End If
' 0:nnwwn 1:wnnnw 2:nwnnw 3:wwnnn 4:nnwnw 5:wnwnn 6:nwwnn 7:nnnww 8:wnnwn 9:nwnwn
BinaryNum = Array("nnwwn", "wnnnw", "nwnnw", "wwnnn", "nnwnw", "wnwnn", "nwwnn", "nnnww", "wnnwn", "nwnwn")

For a = 1 To Len(Numbers1)
'num2 = BinaryNum(a)
BinArray(a) = BinaryNum(Mid(Numbers1, a, 1))
Debug.Print a & " " & Mid(Numbers1, a, 1) & " " & BinArray(a)
If a Mod 2 Then
Else
For b = 1 To 5
ConvertedNum = ConvertedNum & UCase(Mid(BinArray(a - 1), b, 1)) & Mid(BinArray(a), b, 1)
Next
End If
Next
I25 = "(" & ConvertedNum & ")"
End Function

Can this run in Crystal reports or does in need changed?

DougP, MCP
 
It needs to be changed.

If remainder(Len(Numbers)/2) <> 0 Then
'Odd number, add leading zero
Numbers1 := &quot;0&quot; & Numbers
Else
'WE have an even number of characters
Numbers1 := Numbers
End If

and change:

stringvar array BinaryNum := [&quot;nnwwn&quot;, &quot;wnnnw&quot;, &quot;nwnnw&quot;, &quot;wwnnn&quot;, &quot;nnwnw&quot;, &quot;wnwnn&quot;, &quot;nwwnn&quot;, &quot;nnnww&quot;, &quot;wnnwn&quot;, &quot;nwnwn&quot;]

This part looks wrong:

If a Mod 2 Then
Else
For b = 1 To 5
ConvertedNum = ConvertedNum & UCase(Mid(BinArray(a - 1), b, 1)) & Mid(BinArray(a), b, 1)
Next
End If

There's nothing after the Then

The rest isn't too hard to hammer out, just slight syntax and implementation differences.

-k
 
The reason the is nothing after the THEN is becasue if the number is odd then there is nothing to do. it only needs to do something on an even number
It takes pairs of numbers and creates a barcode

DougP, MCP
 
Is there a LOOP function in Crystal 7.0 ???

like For Next or Do Loop or While Wend

DougP, MCP
 
Looping didn't start in Crstal until Version 8

Mike
 
Ok can you provide a sample in ver 8.0
Is if &quot;FOR&quot; or ?????

DougP, MCP
 
Use Boolean logic for this sort of thing:

The reason the is nothing after the THEN is becasue if the number is odd then there is nothing to do. it only needs to do something on an even number
It takes pairs of numbers and creates a barcode

might be:

If not(a Mod 2) Then
For b = 1 To 5
ConvertedNum = ConvertedNum & UCase(Mid(BinArray(a - 1), b, 1)) & Mid(BinArray(a), b, 1)
Next
End If

Which version of Crystal are you using?

A loop in CR 8 and above looks like:

whileprintingrecords;
stringvar AddedValue;
numbervar x;
for x := 1 to 100 do(
if {table.field} = &quot;Some value&quot; then
AddedValue := AddedValue+{table.field}
);
AddedValue

-k
 
I have ver 8.5
Can you help me with the whole thing??
I don't know Crystal this is for a customer.

DougP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top