 |
Das deutsche QBasic- und FreeBASIC-Forum Für euch erreichbar unter qb-forum.de, fb-forum.de und freebasic-forum.de!
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
The_Muh aka Mark Aroni

Anmeldungsdatum: 11.09.2006 Beiträge: 718
|
Verfasst am: 04.08.2007, 15:36 Titel: Problem mit textverarbeitung |
|
|
Ich hab ein problem
kann ich die arrow-tasten nicht mit einbinden (multikey und input$ + CHR$() funzen nicht)
hier der code (die nicht funzenden arrows hab ich rauseditiert):
Code: | dim as integer b, x, y, sterne
dim as string a, d, text
screen 0
width 50, 27 ' ich werd bald ne funktion einbauen umd die höhe um breite zu verstellen
'da sonst die texte begrenzt sind
locate 1, 1:
PRINT "|Muh-Text||+ = Laden | ESC = Quit | # = speichern|"
locate 2, 1
Print "--------------------------------------------------"
x = 3
y = 1
do
anfang:
d = INPUT$(1)
if d = CHR$(43) then
locate x, y
text = LEFT (text,len(text)-1)
if y > 1 then y -= 1 else Y = 1
locate 3, 1
Print " ";
OPEN "muhtext.txt" FOR INPUT AS #1
INPUT #1, a
CLOSE #1
print a
end if
if d = CHR$(8) then 'backspace
text = LEFT (text,len(text)-1)
if y > 1 then y -= 1
if y = 1 then
end if
locate x, y :
Print " ";
goto anfang
end if
if d <> CHR$(13) or a <> CHR$(35) then 'alle andern tasten
locate x ,y : Print d;
y += 1
text = text + d
end if
if d = CHR$(13) then 'enter
x += 1
y = 1
end if
If d = CHR$(35) then
text = LEFT (text,len(text)-1)
if y > 1 then y -= 1
locate x, y
Print " ";
OPEN "myfile.txt" FOR OUTPUT AS #1
WRITE #1, text,
CLOSE #1
OPEN "muhtext.txt" FOR INPUT AS #1
INPUT #1, a
CLOSE #1
Beep
end if
loop until d = CHR$(27)
locate 1, 1:
PRINT "| Texteditor | Das Programm wird geschlossen! |"
sleep
|
ich hab vor meine passwortabfrage in das programm mit einfliesen zu lassen... eventuel als tagebuch  _________________ // nicht mehr aktiv // |
|
Nach oben |
|
 |
ytwinky

Anmeldungsdatum: 28.05.2005 Beiträge: 2624 Wohnort: Machteburch
|
Verfasst am: 04.08.2007, 16:07 Titel: |
|
|
Die Pfeiltasten liefern zwei Ascii-Werte, wenn sie mit Inkey abgefragt werden: FB-Referenz hat Folgendes geschrieben: | #Define FKey Chr(255)
#Define kc_Left FKey + "K"
#Define kc_Right FKey + "M"
#Define kc_Up FKey + "H"
#Define kc_Down FKey + "P"
#Define kc_Pos1 FKey + "G"
#Define kc_End FKey + "O"
#Define kc_Ins FKey + "R"
#Define kc_Del FKey + "S" | ..du mußt also erst prüfen, ob das erste Zeichen=Fkey ist und kannst dann prüfen, ob das 2. eine Pfeiltaste ist..
Ich kanns nicht lassen: http://ytwinky.freebasic.de/freebasic/inputln.bas
oder FoSu nach 'iNPutLn()'.. _________________
v1ctor hat Folgendes geschrieben: | Yeah, i like INPUT$(n) as much as PRINT USING.. | ..also ungefähr so, wie ich GOTO.. |
|
Nach oben |
|
 |
AndT
Anmeldungsdatum: 02.04.2007 Beiträge: 481
|
Verfasst am: 04.08.2007, 17:04 Titel: |
|
|
Ein ganz einfaches Beispielprogramm dafür
Code: | dim as integer x,y
dim as string eingabe
DO
Eingabe=inkey
SELECT CASE Eingabe
case chr(255)+"K" : y-=1
case chr(255)+"M" : y+=1
case chr(255)+"H" : x-=1
case chr(255)+"P" : x+=1
end select
locate 1,1:Print x,y
locate x,y:print "x"
LOOP |
_________________ Bis irgendwann...  |
|
Nach oben |
|
 |
PMedia
Anmeldungsdatum: 14.08.2006 Beiträge: 2847
|
Verfasst am: 04.08.2007, 17:09 Titel: |
|
|
MultiKey sollte aber egtl. gehen.
Code: |
#include "fbgfx.bi"
do
if multikey(fb.sc_up) then print "Lass sofort die Pfeil-nach-Oben-Taste los!"
if multikey(fb.sc_down) then print "Lass sofort die Pfeil-nach-Unten-Taste los!"
if multikey(fb.sc_left) then print "Lass sofort die Pfeil-nach-Links-Taste los!"
if multikey(fb.sc_right) then print "Lass sofort die Pfeil-nach-Rechts-Taste los!"
sleep 1
loop until multikey(fb.sc_escape)
|
(Code ab 0.17 lauffähig, ältere Versionen bitte fb. in jedem Multikey entfernen) |
|
Nach oben |
|
 |
Eternal_pain

Anmeldungsdatum: 08.08.2006 Beiträge: 1783 Wohnort: BW/KA
|
Verfasst am: 04.08.2007, 17:14 Titel: |
|
|
Multikey erfordert aber immer eine reihe von If/Then und das schleift
@AndT
ubersichtlicheres Coden und Abbruchmoeglichkeit solltes Dir mal angewoehnen
Code: |
dim as integer ox,oy
dim as integer x,y
dim as string eingabe
DO
Eingabe=inkey
SELECT CASE Eingabe
case chr(255)+"K"
x-=1
case chr(255)+"M"
x+=1
case chr(255)+"H"
y-=1
case chr(255)+"P"
y+=1
end select
x=iif(x=0,1,x)
x=iif(x>80,80,x)
y=iif(y=0,1,y)
y=iif(y>25,25,y)
If x<>ox or y<>oy Then
locate oy,ox,0:?" ";
ox=x
oy=y
locate 1,1,0:Print x,y
locate y,x,0:print "x";
End if
sleep 1
LOOP until multikey(&h01)
|
_________________
 |
|
Nach oben |
|
 |
ytwinky

Anmeldungsdatum: 28.05.2005 Beiträge: 2624 Wohnort: Machteburch
|
Verfasst am: 04.08.2007, 18:29 Titel: |
|
|
Meinst du so, wie bei MarineDon?
http://www.smithselfgen.com/QuickBasic/EDITQB.BAS _________________
v1ctor hat Folgendes geschrieben: | Yeah, i like INPUT$(n) as much as PRINT USING.. | ..also ungefähr so, wie ich GOTO.. |
|
Nach oben |
|
 |
The_Muh aka Mark Aroni

Anmeldungsdatum: 11.09.2006 Beiträge: 718
|
Verfasst am: 04.08.2007, 19:56 Titel: |
|
|
Hoch und runter geht... aber echts und links nicht... und es erschein immer ein Output (H,M,K oder P) je nach dem was man drückt
Code: |
eingabe=inkey
if multikey(fb.sc_up) then
x -=1
end if
if multikey(fb.sc_down) then
x +=1
end if
if multikey(fb.sc_left) then
y -=1
end if
if multikey(fb.sc_right) then
y +=1
end if
| [/quote] _________________ // nicht mehr aktiv // |
|
Nach oben |
|
 |
Eternal_pain

Anmeldungsdatum: 08.08.2006 Beiträge: 1783 Wohnort: BW/KA
|
Verfasst am: 04.08.2007, 20:10 Titel: |
|
|
geht, problemlos.... und FAST (<- nicht zu verwechseln mit fast )
Code: |
#include "fbgfx.bi"
dim as integer ox,oy
dim as integer x,y
dim as string eingabe
DO
Eingabe=inkey
if multikey(fb.sc_up) then
y -=1
end if
if multikey(fb.sc_down) then
y +=1
end if
if multikey(fb.sc_left) then
x -=1
end if
if multikey(fb.sc_right) then
x +=1
end if
x=iif(x=0,1,x)
x=iif(x>80,80,x)
y=iif(y=0,1,y)
y=iif(y>25,25,y)
If x<>ox or y<>oy Then
locate oy,ox,0:?" ";
ox=x
oy=y
locate 1,1,0:Print x,y
locate y,x,0:print "x";
End if
sleep 1
LOOP until multikey(&h01)
|
_________________
 |
|
Nach oben |
|
 |
The_Muh aka Mark Aroni

Anmeldungsdatum: 11.09.2006 Beiträge: 718
|
Verfasst am: 04.08.2007, 22:23 Titel: |
|
|
hab deinen code angepasst und eingebaut, allerdings schein ich irgentwas falsch zu machen... ich stell meinen derzeitigen code mal rein:
Code: | #include "fbgfx.bi"
dim as integer b, x, y, sterne, zaehler
dim as string a, d, text, eingabe
dim as integer ox,oy
screen 0
width 50, 27 ' ich werd bald ne funktion einbauen umd die höhe um breite zu verstellen
'da sonst die texte begrenzt sind
locate 1, 1:
PRINT "|Muh-Text||+ = Laden | ESC = Quit | # = speichern|"
locate 2, 1
Print "--------------------------------------------------"
x = 3
y = 1
DO
anfang:
d=inkey
if multikey(fb.sc_up) then
y -=1
end if
if multikey(fb.sc_down) then
y +=1
end if
if multikey(fb.sc_left) then
x -=1
end if
if multikey(fb.sc_right) then
x +=1
end if
x=iif(x=0,1,x)
x=iif(x>50,50,x)
y=iif(y=0,1,y)
y=iif(y>27,27,y)
If x<>ox or y<>oy Then
locate oy,ox,0:?" ";
ox=x
oy=y
locate 1,1,0:Print x,y
locate y,x,0:print "x";
End if
if d = CHR$(43) then
locate x, y
text = LEFT (text,len(text)-1)
if y > 1 then y -= 1
locate x, y
Print " ";
OPEN "muhtext.txt" FOR INPUT AS #1
INPUT #1, text
CLOSE #1
locate x, y
print text
end if
if d = CHR$(8) then 'backspace
if y > 1 then
y -= 1
text = LEFT (text,len(text)-1)
locate x, y :
Print " ";
end if
goto anfang
end if
if d <> CHR$(13) or a <> CHR$(35) then 'alle andern tasten
locate x ,y : Print d;
y += 1
text = text + d
end if
if d = CHR$(13) then 'enter
if x > 26 then
x = 3
y = 1
else
y = 1
x += 1
end if
end if
If d = CHR$(35) then
text = LEFT (text,len(text)-1)
if y > 1 then y -= 1
locate x, y
Print " ";
OPEN "myfile.txt" FOR OUTPUT AS #1
WRITE #1, text,
CLOSE #1
OPEN "muhtext.txt" FOR INPUT AS #1
INPUT #1, a
CLOSE #1
Beep
end if
loop until d = CHR$(27)
locate 1, 1:
PRINT "| Texteditor | Das Programm wird geschlossen! |"
sleep
|
Das problem ist, das die beiden obersten zeilen (die nicht verändert werden sollen, gelöscht werden) und das die normale eingabe nicht mehr möglich ist...
entweder muss dein code in ne eigene do - loop schleife oder er muss weiter angepasst werden... außerdem verändert sich die position des coursers nicht zeichenweise sondern spricht von 1 nach 27 (in der höhe) bzw. von 1 nach 50 (breite)...
notfalls machen wir 'n gemeinschaffts-projekt draus (dann als tagebuch wie oben erwähnt) _________________ // nicht mehr aktiv // |
|
Nach oben |
|
 |
The_Muh aka Mark Aroni

Anmeldungsdatum: 11.09.2006 Beiträge: 718
|
Verfasst am: 06.08.2007, 06:38 Titel: |
|
|
Da ich beschlossen hab ein Tagebuch zu programmieren, komme ich nicht drumherum ein schiffre-decoder und encoder zu schreiben... schiffre, weil der code feststehend ist (momentan)
eigentlich klappt das auch ganz gut... nur hab ich 2 probleme:
erstens dauert es bei längeren strings (was bei tagebüchern ja so der fall ist) ewig bis der string ausgewertet und verarbeitet ist...
2 gibt er nicht den completten schiffre code aus, wenn man einzeln zahlen und buchstaben eingibt... längere strings weisen auch fehler auf...
hier der quell-code (ohne mein schiffre, weil der mich 2 stunden gekostet hat)
Code: | declare sub decoder
Sub decoder
DIM as string text1, text2
DIM as integer x , y , zaehler, laenge
y = 0
zaehler = 0
Input "bitte text eingeben", text1
laenge = len (text1)
do
y = instr (text1,"a")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"b")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"c")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
end if
y = instr (text1,"d")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"e")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"f")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"g")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"h")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"i")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"j")
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"k")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"l")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"m")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"n")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"o")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"p")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"q")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"r")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"s")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"t")
if y > 0 then
text2 = MID (text1, y+2)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"u")
if y > 0 then
text2 = MID (text1, y+3)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"v")
if y > 0 then
text2 = MID (text1, y+3)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"w")
if y > 0 then
text2 = MID (text1, y+3)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"x")
if y > 0 then
text2 = MID (text1, y+3)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"y")
if y > 0 then
text2 = MID (text1, y+3)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
y = instr (text1,"z")
if y > 0 then
text2 = MID (text1, y+3)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
loop until zaehler = laenge
sleep
end sub
|
_________________ // nicht mehr aktiv // |
|
Nach oben |
|
 |
nemored

Anmeldungsdatum: 22.02.2007 Beiträge: 4704 Wohnort: ~/
|
Verfasst am: 06.08.2007, 07:36 Titel: |
|
|
Mit einer Schleife wäre das ganze kürzer:
Code: | for i=asc("a") to asc("j")
y = instr (text1,chr(i))
if y > 0 then
text2 = MID (text1, y+1)
MID (text1, y, 3) = "code"
text1 += text2
zaehler += 1
end if
next |
usw.
MID (text1, y, 3) = "code" gibt Probleme, weil FB die eine Stringlänge an die andere anpasst. In deinem Fall wird "code" auf "cod" verkürzt, damit es in die drei Zeichen von MID (text1, y, 3) hineinpasst (ein bescheuertes Verhalten, aber ist halt so). _________________ Deine Chance beträgt 1:1000. Also musst du folgendes tun: Vergiss die 1000 und konzentriere dich auf die 1. |
|
Nach oben |
|
 |
The_Muh aka Mark Aroni

Anmeldungsdatum: 11.09.2006 Beiträge: 718
|
Verfasst am: 06.08.2007, 07:51 Titel: |
|
|
d.h. ich muss den string um das zeichen verkürzen und die zeichenkette dranhängen?!?!
das problem dabei ist, das der Code für jeden buchstaben 'n anderen wert hat (fäng bei 800 geht bis 90000) _________________ // nicht mehr aktiv // |
|
Nach oben |
|
 |
nemored

Anmeldungsdatum: 22.02.2007 Beiträge: 4704 Wohnort: ~/
|
Verfasst am: 06.08.2007, 08:00 Titel: |
|
|
Dann lege ein Array an, in dem du für jeden Buchstaben den Chiffre-Code speicherst.
Es wird übrigens immer nur das erste auftretende a verschlüsselt usw. Ist das Absicht?
Die Ersatzfunktion für MID musst du dir halt mit LEFT und MID zusammenbasteln:
Code: | text1 = LEFT(text1, y-1) + "code" + MID(text1, y+4) |
(ohne Gewähr) _________________ Deine Chance beträgt 1:1000. Also musst du folgendes tun: Vergiss die 1000 und konzentriere dich auf die 1. |
|
Nach oben |
|
 |
The_Muh aka Mark Aroni

Anmeldungsdatum: 11.09.2006 Beiträge: 718
|
Verfasst am: 06.08.2007, 08:50 Titel: |
|
|
so viele strings hab ich noch nich getestet... aber ich kann mich momentan nich wirklich konzentrieren... hab schon meine 3te tasse kaffee intus... und bin seid 15 uhr (gestern) wach... tolle kombination um sich zu konzentrieren xD
/edit: kanne leer... ich geh gleich mal neuen kaffee kochen *muahaha* _________________ // nicht mehr aktiv // |
|
Nach oben |
|
 |
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
|