Page 1 of 1

Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 1:55 pm
by Szven
Hey, i want to make a programm where you can typ a text in and it swaps every letter (every a, b ,c and so on) vom the input text with every letter from a to z but i dont know how to make this, maybe one of you can help me i´m trying it for hours.

(Yes I´m started to learn just a few days ago but need this for school)

Hope for a nice tipp or solution

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 2:22 pm
by shadow
Show us some code worked out by you and we will try to help you to complete the task :wink:

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 2:47 pm
by ts-soft

Code: Select all

Procedure SubClassCB(hWnd, uMsg, wParam, lParam)
  Protected oldproc = GetProp_(hWnd, "oldproc")

  Select uMsg
    Case #WM_NCDESTROY
      RemoveProp_(hWnd, "oldproc")
    Case #WM_CHAR
      wParam + 1
  EndSelect
 ProcedureReturn CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
EndProcedure

Procedure SubClassGadget(ID)
  Protected oldproc = SetWindowLongPtr_(GadgetID(ID), #GWL_WNDPROC, @SubClassCB())
  ProcedureReturn SetProp_(GadgetID(ID), "oldproc", oldproc)
EndProcedure

OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "")
EditorGadget(0, 5, 5, 630, 470)
SubClassGadget(0)
SetActiveGadget(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 3:39 pm
by Szven
started with:
test$ = "Sven"
ReplaceString(test$, "S", "H", #PB_String_InPlace, 1)
Debug test$
because for me it was the only good command I found in the reference, but i can´t add more letters like:
test$ = "Sven"
ReplaceString(test$, "S +, V", "H ,+ B", #PB_String_InPlace, 1)
Debug test$
or
test$ = "Sven"
ReplaceString(test$, "S", "H","V", "B", #PB_String_InPlace, 1)
Debug test$

Becaus I thought that this is the right way to add more solutions. But this just make my debugger pop up. I believ that I just have to know how to let the programm change every eg. "a" with all letters, cause than i would try so long till there is a solution. But now there is no solution for me

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 4:02 pm
by xorc1zt

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 9:00 pm
by charvista
Sven (or Szven),
Nobody understood what you were trying to accomplish. You have to be very clear with what you want to do. You said: [... and it swaps every letter]. How swapped? There are many ways and directions to swap!
From your attempt, I finally understood that you want to swap the whole alphabet, so that when you type the letter A, you want to see the letter Z on the screen, and when you type a B, Y should be displayed and so on.
I guessed it solely with the letters S and H you showed in your attempt, and indeed, S is the 8th letter of the alphabet, counted from Z, like the H which is also the 8th letter! :mrgreen:

And because you are very new in programming, try to understand the logic with a simple table.

Code: Select all

Table1$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; the normal alphabet
Table2$="ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"; the reversed alphabet

Test$="Sven is the best at school !"; the word that you want to "swap"

For i=1 To Len(Test$); we make a loop for each letter in Test$
    Pos=FindString(Table1$,Mid(Test$,i,1)); we get the position of the letter in the normal alphabet (Table1$)
    If Pos=0; if the letter is not found
        New$=New$+Mid(Test$,i,1); we put the same letter or symbol in the new word
    Else
        New$=New$+Mid(Table2$,Pos,1); we put the corresponding letter in the new word
    EndIf
Next

Debug New$; and finally we want to see the new word!
:wink:

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 9:11 pm
by juror
Since there may be "solution" replies, it would be helpful if the topic reflected the actual problem for which solutions may be suggested.

This will help any future searches. :)

Re: Easy problem for most of you very hard for me

Posted: Tue Apr 24, 2012 10:11 pm
by xorc1zt
here is a little trick, only work for ascii and no caps.

Code: Select all

define str.s = "abcdef"
define *ptr = @str

repeat
    pokeb( *ptr, 122 - ( peekb( *ptr ) - 97 ) )
    *ptr+1
until peekc(*ptr) = 0

debug str
 

Re: Easy problem for most of you very hard for me

Posted: Wed Apr 25, 2012 6:44 am
by wilbert
A little variation on the code above that works for both upper and lowercase characters

Code: Select all

Define str.s = "Abcdef Gh"
Define *ptr.Character = @str

While *ptr\c
  If *ptr\c & 64
    *ptr\c = *ptr\c ! 31 - 4
  EndIf
  *ptr + SizeOf(Character)
Wend

Debug str

Re: Easy problem for most of you very hard for me

Posted: Wed Apr 25, 2012 4:32 pm
by luis
"Easy problem for most of you very hard for me"

Great example of a bad title for a post. Can you guess why ? Try.