Funny I put the 2nd code in IDE and nothing, no red lines, nothing...
Do you have demo code that calls up the SUB you made? That might get a response from red lines :-))
I cant read the Italian but it looks like a hand made INPUT$ routine that controls what letters and length of input, correct?
I dont think I've ever seen STATIC on same line as SUB definition and I dont think SHARED works in a SUB, not sure but... my first impressions...
Your SUB needs to know what valido$ is, it's thinking it's "" nothing.
And INSTR does work right with nothing.
Still not right but now you can see something!Code: QB64: [Select]
I got rid of the shared and made valido$ part of the input.
This line defines the SUB and its parameters (variables for now):Code: QB64: [Select]
IMPORTANT: You do not have to use the same variable names as you used defining the SUB, ie
In main code you don't have to say:Code: QB64: [Select]
ottieneinput max%, buffer$
You could say:Code: QB64: [Select]
ottieneinput charactersLimit%, myInputString$
Here is the SUB fixed perfecto! (Just kidding, millions of ways to write this.)Code: QB64: [Select]
''DIM SHARED valido$ >>>>>>>>>>>>> there is another way to tell the SUB what valido$ = lc$ = "abcdefghijklmnopqrstuvwxyz" ' missing jk nu$ = "0123456789-+/." valido$ = lc$ + uc$ + nu$ ' <<< lower case, uppercase and digits CharacterLimit% = 5 ' <<<<<<<<<<<<<<< limit 5 anyString$ = "" 'nothing ' best to start with blank ottieneinput CharacterLimit%, anyString$, valido$ buffer$ = "" 'just in case it was something ' LOCATE 1, 1: PRINT max%, buffer$, Good$ ' <<< debugging tastopremuto$ = INKEY$ buffer$ = "" BEEP ' it's already empty ELSE ' << if good letter or digit add it onto buffer$ buffer$ = buffer$ + tastopremuto$ BEEP 'signal buffer$ is full
@Kiara87 your alphabet is missing jk but looks like you've got it working. :)
riguardo al bug del backspace esso è dovuto alla parte di output del programma e non ai calcoli interni
se cancelli la lineaCode: QB64: [Select]e prima diCode: QB64: [Select]inserisci
lunghezza% = lunghezza% - 1Code: QB64: [Select]mentre dopoCode: QB64: [Select]aggiungi
Code: QB64: [Select]e l'errore di output è sistemato... ma non so perchè nella versione spaghetticode questa linea di codiceCode: QB64: [Select]funziona mentre in quella modulare no!
English version:
About the bug of backspace it is in the output part of the program and not in the part of internal calculation/computation,
if you cancel the line of codeCode: QB64: [Select]and beforeCode: QB64: [Select]you insert
lunghezza% = lunghezza% - 1Code: QB64: [Select]and after
Code: QB64: [Select]you add
Code: QB64: [Select]the output part is fixed.... but I dunno why in the spaghetti code version this line of codeCode: QB64: [Select]works while in the modular one it doesn't!
PS Hey don't you hurt all these alternating white, grey, black rows ?
Codice intero /whole codeCode: QB64: [Select]
' area di inizializzazione dei dati / area of initializing data 10 lc$ = "abcdefghilmnopqrstuvwxyz" 30 nu$ = "0123456789-+/." 40 valido$ = uc$ + lc$ 'una stringa contenente tutti i caratteri validi 50 buffer$ = "" ' buffer per il nome 60 max% = 30 'numero massimo di caratteri ottieneinput max%, buffer$ ' chiama o salta alla SUB e poi torna qui END ' termina il programma '<----------------------------this is the main of program that lacks into second code that you posted -----------> ' area SUB / FUNCTION--------------- SHARED valido$ lunghezza% = 0 tastopremuto$ = INKEY$ lunghezza% = lunghezza% - 1 buffer$ = buffer$ + tastopremuto$
' main
inizialize
AskInput
Loop
GetInput
IF... BackSpace
IF .....AddNewCharacter
IF... END
AdjournOutput
SUB inizialize
END SUB
SUB GetInput
End SUB
SUB AskInput
END SUB
SUB BackSpace
END SUB
SUB AddNewCharacter
END SUB
SUB AdjournOutput
END SUB