Easy problem for most of you very hard for me

Just starting out? Need help? Post your questions and find answers here.
Szven
New User
New User
Posts: 2
Joined: Tue Apr 24, 2012 1:49 pm

Easy problem for most of you very hard for me

Post 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
User avatar
shadow
User
User
Posts: 34
Joined: Thu Dec 16, 2010 1:25 pm
Location: Germany

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

Post by shadow »

Show us some code worked out by you and we will try to help you to complete the task :wink:
ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Szven
New User
New User
Posts: 2
Joined: Tue Apr 24, 2012 1:49 pm

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

Post 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
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

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

Post 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:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
juror
Enthusiast
Enthusiast
Posts: 228
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

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

Post 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. :)
xorc1zt
Enthusiast
Enthusiast
Posts: 276
Joined: Sat Jul 09, 2011 7:57 am

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

Post 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
 
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply