08-29-2023, 11:11 PM
(This post was last modified: 08-29-2023, 11:15 PM by Kernelpanic.)
The function expects a double, but should return a string. Is this possible?
It is about replacing the Saxon point with a comma in a German edition. The program works, and I want to wrap that in a function. But the function doesn't want to.
"Illegal string-number conversion" - where? Maybe someone knows where the error is? Thanks!
This is OK:
The function gives the error message (punktKomma = zk_zahl -- Line 50)
It is about replacing the Saxon point with a comma in a German edition. The program works, and I want to wrap that in a function. But the function doesn't want to.
"Illegal string-number conversion" - where? Maybe someone knows where the error is? Thanks!
This is OK:
Code: (Select All)
'Punkt in der Zahlenausgabe durch Komma ersetzen - 28. Aug. 2023 'Aus: SB S.100 Option _Explicit Dim As Double zahl Dim As Integer punkt_position Dim As String zk_zahl Print "Eingegebene Zahl mit Komma ausgeben" Print Input "Zahl: ", zahl 'In Zeichenkette umwandeln zk_zahl = Str$(zahl) 'Position des Punktes ermitteln punkt_position = InStr(zk_zahl, ".") 'Punkt durch Komma ersetzen - Mid$-Anweisung If punkt_position <> 0 Then Mid$(zk_zahl, punkt_position) = "," End If Print "Zahl nach deutscher Notation: "; zk_zahl End
The function gives the error message (punktKomma = zk_zahl -- Line 50)
Code: (Select All)
'Punkt in der Zahlenausgabe durch Komma ersetzen - 28. Aug. 2023 'Aus: SB S.100 Option _Explicit Declare Function punktKomma(dEingabe As Double) As String Dim As Double zahl Dim As Integer punkt_position Dim As String zk_zahl Print "Eingegebene Zahl mit Komma ausgeben" Print Input "Zahl: ", zahl 'In Zeichenkette umwandeln zk_zahl = Str$(zahl) 'Position des Punktes ermitteln punkt_position = InStr(zk_zahl, ".") 'Punkt durch Komma ersetzen - Mid$-Anweisung If punkt_position <> 0 Then Mid$(zk_zahl, punkt_position) = "," End If Print "Zahl nach deutscher Notation: "; zk_zahl Print 'Warum ueber Val(x) gehen? Der Ursprungswert ist doch da. zahl = zahl * 3 Print Using "Eingabe * 3 = ####.##"; zahl End Function punktKomma (dEingabe As Double) Dim As Integer punkt_position Dim As String zk_zahl zk_zahl = Str$(dEingabe) punkt_position = InStr(zk_zahl, ".") If punkt_position <> 0 Then Mid$(zk_zahl, punkt_position) = "," End If punktKomma = zk_zahl End Function