Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with one function
#1
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:
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
Reply


Messages In This Thread
Problem with one function - by Kernelpanic - 08-29-2023, 11:11 PM
RE: Problem with one function - by DSMan195276 - 08-29-2023, 11:14 PM
RE: Problem with one function - by SMcNeill - 08-29-2023, 11:15 PM
RE: Problem with one function - by Kernelpanic - 08-29-2023, 11:26 PM



Users browsing this thread: 6 Guest(s)