Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
12-16-2022, 12:53 AM
(This post was last modified: 12-16-2022, 01:04 AM by Kernelpanic.)
Thank you for the hints. I think I now know why you just have to specify the path to an external program.
Now I tried to write a function that one enter the respective external program. But I get an error message that I can't do anything with. I searched the internet but could not find anything that explained the error message. - Even the error message I can't fully understand. "Illegal string-number conversion" . . . where is there a string-number?
Due to this error message I was unfortunately not able to check whether this function would work at all.
Code: (Select All) 'Externes Programm aufrufen mit Funktion - 15. Dez. 2022
Option _Explicit
Declare Function externesProgramm(extern As String) As String
Print "D:\" + Chr$(34) + "Program Files" + Chr$(34) + "\Notepad++\notepad++.exe tmp.three"
Function externesProgramm (extern As String)
Dim As String pfad
pfad = extern
externesProgramm = pfad
End Function
End
It is: externesProgramm = pfad
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
(12-15-2022, 02:39 PM)Spriggsy Wrote: I'm so confused. How does Notepad++ play a role in the chat program?
The Notepad++ problem starts here:
https://staging.qb64phoenix.com/showthre...6#pid11386
Posts: 1,616
Threads: 157
Joined: Apr 2022
Reputation:
77
12-16-2022, 02:19 AM
(This post was last modified: 12-16-2022, 02:20 AM by Pete.)
(12-16-2022, 12:53 AM)Kernelpanic Wrote: Thank you for the hints. I think I now know why you just have to specify the path to an external program.
Now I tried to write a function that one enter the respective external program. But I get an error message that I can't do anything with. I searched the internet but could not find anything that explained the error message. - Even the error message I can't fully understand. "Illegal string-number conversion" . . . where is there a string-number?
Due to this error message I was unfortunately not able to check whether this function would work at all.
Code: (Select All) 'Externes Programm aufrufen mit Funktion - 15. Dez. 2022
Option _Explicit
Declare Function externesProgramm(extern As String) As String
Print "D:\" + Chr$(34) + "Program Files" + Chr$(34) + "\Notepad++\notepad++.exe tmp.three"
Function externesProgramm (extern As String)
Dim As String pfad
pfad = extern
externesProgramm = pfad
End Function
End
It is: externesProgramm = pfad
Code: (Select All) 'Externes Programm aufrufen mit Funktion - 15. Dez. 2022
OPTION _EXPLICIT
Declare Function externesProgramm$(extern As String) As String
PRINT "D:\" + CHR$(34) + "Program Files" + CHR$(34) + "\Notepad++\notepad++.exe tmp.three"
END
FUNCTION externesProgramm$ (extern AS STRING)
DIM AS STRING pfad
pfad = extern
externesProgramm = pfad
END FUNCTION
Pete
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
Thanks, Pete! I would not have thought of the "$" next to the function.
The program works now. One more note, without "Console" one can not enter "\".
Code: (Select All) 'Externes Programm aufrufen mit Funktion - 15. Dez. 2022
'Korrektur durch Pete bei der Funktion "$" - 16. Dez. 2022
'Ohne "Console" kann "\" nicht eingegeben werden
$Console:Only
Option _Explicit
Declare Function externesProgramm(extern As String) As String
Dim As String externerAufruf
Input "Externes Programm: ", externerAufruf
Shell _Hide _DontWait "D:\" + Chr$(34) + "Program Files" + Chr$(34) + externesProgramm(externerAufruf)
End
Function externesProgramm$ (extern As String)
Dim As String pfad
pfad = extern
externesProgramm = pfad
End Function
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
I have now expanded the program so that you can specify the location of the program. I have programs under both " Programme" and " Program Files". -- By the way, I myself have never created a " Program Files" directory, the installation routines always specify that. I created the " Programme" folder because, for example, Strawberry Perl does not like " Program Files".
Code: (Select All) 'Externes Programm aufrufen mit Funktion - 15. Dez. 2022
'Korrektur durch Pete bei der Funktion "$" - 16. Dez. 2022
'Ohne "Console" kann "\" nicht eingegeben werden
$Console:Only
Option _Explicit
Declare Function externesProgramm(extern As String) As String
Dim As String externerAufruf
Dim As Integer auswahl
Locate 2, 3
Print "Aufruf externer Programme"
Locate 3, 3
Print "========================="
Locate 5, 3
Print "Bestimmung des Programmortes."
Locate 6, 3
Print "Programme ist: 1 -- Program Files ist 2"
Locate 8, 3
Input "Auswahl: ", auswahl
Locate 10, 3
If auswahl = 1 Then
Input "Externes Programm: ", externerAufruf
Shell _Hide _DontWait "D:\" + Chr$(34) + "Programme" + Chr$(34) + externesProgramm(externerAufruf)
Else
Input "Externes Programm: ", externerAufruf
Shell _Hide _DontWait "D:\" + Chr$(34) + "Program Files" + Chr$(34) + externesProgramm(externerAufruf)
End If
End
Function externesProgramm$ (extern As String)
Dim As String pfad
pfad = extern
externesProgramm = pfad
End Function
Example:
Posts: 1,510
Threads: 53
Joined: Jul 2022
Reputation:
47
12-16-2022, 11:24 PM
(This post was last modified: 12-16-2022, 11:26 PM by mnrvovrfc.)
(12-16-2022, 04:56 PM)Kernelpanic Wrote: Thanks, Pete! I would not have thought of the "$" next to the function.
Maybe you and I should campaign so the "AS TYPE" clause could be put at the end of a function header. Do you use Freebasic or Visual Basic? You have to try to remember QB64(PE) still requires the type sigils, whatever they are, right after a function's name in the header, and nothing except "STATIC" right after the closing parenthesis of the parameter list.
It should have been easy to remember that any string function in QB64(PE) must carry the dollar sign at the end of the name! Like "MID$", "STR$", "SPACE$" and so on.
Instead of:
function addtwo (one as long, two as long) as long
you must write it:
function addtwo& (one as long, two as long)
You write code in the other BASIC, and then you should load it into the QB64 IDE, which should flag the errors of "AS TYPE". Then you should know which sigil for which type.
https://qb64phoenix.com/qb64wiki/index.p...able_Types
EDIT: Why isn't the "DECLARE" line flagged as an error? Maybe it's what allows the user's function to be used without the dollar sign. (facepalm)
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
I can not comprehend why a type declaration has to be attached to the function name here:
Code: (Select All) Declare Function externesProgramm(extern As String) As String
. . .
Function externesProgramm$ (extern As String)
Dim As String pfad
pfad = extern
externesProgramm = pfad
End Function
. . . but not here:
Code: (Select All) Option _Explicit
Declare Function endkapital (einzahlung as double, q as double, zeit as integer) As Double
Dim As Double einzahlung, zinssatz, q
Dim zeit As Integer
einzahlung = 2400.00 'Pro Jahr
zinssatz = 3.5
zeit = 21
'Zinsfaktor berechnen
q = (1 + (zinssatz / 100))
Locate 3, 3
Print Using "Das Endkapital betraegt nach ### Jahren: ###,###.## Euro"; zeit, endkapital(einzahlung, q, zeit)
End
Function endkapital (einzahlung As Double, q As Double, zeit As Integer)
Dim kapital As Double
kapital = (einzahlung * ((q ^ zeit) - 1) / (q - 1))
endkapital = kapital
End Function
Posts: 1,616
Threads: 157
Joined: Apr 2022
Reputation:
77
Actually, DECLARE SUB and DECLARE FUNCTION statements are not needed in any QB64 statements. That's an old QBasic holdover.
You can REM them all out and your code examples should run just fine.
Pete
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
(12-17-2022, 06:13 PM)Pete Wrote: Actually, DECLARE SUB and DECLARE FUNCTION statements are not needed in any QB64 statements. That's an old QBasic holdover.
You can REM them all out and your code examples should run just fine.
Pete
Yes, I have noticed that by now. I personally think that is wrong, because the declaration of functions and procedures at the beginning of the source code shows what is coming.
Ok, but I still do not understand why one function needs a type identifier and the other does not.
Posts: 714
Threads: 36
Joined: May 2022
Reputation:
13
I think I know the reason now - the extra type declaration is only necessary for strings.
(Enter -Hello-, I will complete the sentence)
Code: (Select All) Option _Explicit
Declare Function satzErgaenzen(satz As String) As String
Dim As String eingabe
Print
Input "Geben Sie -Hallo- ein, ich ergaenze den Satz: ", eingabe
Print
Print satzErgaenzen(eingabe)
End
Function satzErgaenzen$ (satz As String)
satz = satz + " Fans von QB64!"
satzErgaenzen = satz
End Function
|