First paste some multiline text into top editor, then Build button to see lower editor result.
I have block commented the code & can see working, if un-comment block it will crash.
At some point I was able to debug (in FBedit) & see the code working.
Using Win7Px64
The sub code extracts lines from string retrieved from Editor1 & rebuilds the string for set Editor2 to new string.
Hope someone can help...
Code: Select all
'-------------------------------------------------
' StringTableconv.bas V1.0
' Tool for String Table --> String pointer Table
' Created on 2021-03-17 ToniG
' Last Update 2021- -
'-------------------------------------------------
#Include "WinGUI.bi"
Dim As HWND Window_Main, Editor1, Editor2, Btn_Build, Btn_Copy, Btn_Paste, Btn_Clear, Edit_Font, Btn_Exit
Dim As HFONT hFont
Dim As MSG msg
Dim As Long x0, y0, W1, H1, Rpos
Dim As String Text1
Declare Sub BuildPtrTabl (Editor1 As HWND, Editor2 As HWND)
W1 = 1000 ' Window Width
H1 = 700 ' Window Height
Rpos = 200 ' Right ref
Text1 = "Input: String Table Paste ClipBoard (xxxx)"
' " _" line continuation wont work!!
'Create a window with text editors and a button:
' X Y W H
Window_Main = Window_New (100, 100, W1, H1, "Create String Pointer Table")
' "' Paste Table here..." + Chr(13) + Chr(10) Just for ref. editBox
Editor1 = Editor_New (20, 40, 800, 350, "",, Window_Main)
Editor2 = Editor_New (20, 410, 800, 200, "",, Window_Main)
Var Label_txt1 = Label_New (30, 20, 750, 20, Text1,, Window_Main)
Var Label_txt2 = Label_New (30, 390, 150, 20, "Output: Pointer Table",, Window_Main)
Btn_Paste = Button_New (W1-180, 100, 100, 40, "Paste",, Window_Main)
Btn_Clear = Button_New (W1-180, 100, 100, 40, "Clear",, Window_Main)
Btn_Build = Button_New (W1-180, 100, 100, 40, "Build",, Window_Main)
Btn_Copy = Button_New (W1-180, 100, 100, 40, "Copy",, Window_Main)
Btn_Exit = Button_New (W1-180, 100, 100, 40, "EXIT",, Window_Main)
' ^ Window resize event overides on form open
' Fonts
'hFont = Control_Createfont("Courier New",,, FW_THIN)
hFont = Control_Createfont("Courier New",,, FW_BOLD)
Control_SetFont(Editor1), hFont
Control_SetFont(Editor2), hFont
'--------------------------
Sub BuildPtrTabl (Editor1 As HWND, Editor2 As HWND)
'Sub BuildPtrTabl ()
' Just Testing for now...
' Paste some multi line text from clip board with Paste Button
' All works ok Clear Button, Copy button, editors.
' But if uncommentblock in this sub it crashes with Build button ??
Dim As String TempDS, TmpStr, CRLF, InputString, OutputString, CurrLine, TempString
Dim As Integer ChrPos, StrStrt, LineStrt, CRLFpos, Temp1
Dim As Integer ClosedQuoteCounter, ClosedQuote, EscapeChar
'CRLF = Chr(13) & Chr(10) CRLF = Chr(13, 10) ' < Neither work !!!
InputString = EditBox_GetText(Editor1)
EditBox_SetText(Editor2,InputString) '< For DEBUG
'Above line not even execute with unComment block below !!
/'
LineStrt = -1: TempString = ""
Temp1 = Len(InputString) '< For DEBUG
If Len(InputString) < 2 Then Exit Sub
' SetFocus(Editor2)
EditBox_SetText(Editor2,InputString) '< For DEBUG
'EditBox_SetText(Editor2,"") ' Clear first
'Extract lines from InputString
Do While CRLFpos < Len(InputString)
CRLFpos = InStr(LineStrt + 2, InputString, Chr(13, 10))
CurrLine = Mid(InputString, LineStrt + 2, CRLFpos - (LineStrt -1))
LineStrt = CRLFpos ' < Easier to Debug
TempString &= CurrLine & "---" & Chr(13, 10)
Loop
EditBox_SetText(Editor2,TempString)
'/
End Sub
'-------------------------------
'Event loop:
Do
WaitEvent(Window_Main, msg)
Select Case msg.hwnd
Case Btn_Paste
If msg.message = WM_LBUTTONUP Then
EditBox_Paste(Editor1)
End If
Case Btn_Clear
If msg.message = WM_LBUTTONUP Then
' EditBox_Clear(Editor1) '< This only clears selected text
EditBox_SetText(Editor1,"")
End If
Case Btn_Build
If msg.message = WM_LBUTTONUP Then
BuildPtrTabl(Editor1, Editor2)
' BuildPtrTabl(a,b)
End If
Case Btn_Exit
If msg.message = WM_LBUTTONUP Then
' Hmmmm... HOW TO Close this App ?
End If
Case Btn_Copy
If msg.message = WM_LBUTTONUP Then
' SetWindowText(Editor2, "Copy sets a little text, so that we have something to select")
SetFocus(Editor2)
SendMessage(Editor2, EM_SETSEL, 0, -1)
EditBox_Copy(Editor2)
' How to test if some "is selected" first ??
' SendMessage(Editor2, EM_GETSEL, , )
End If
Case Else
'Resize Controls x if window size change
Window_GetSize(Window_Main, x0, y0, W1, H1)
Control_Resize(Editor1, 20, 40, W1-Rpos, 350)
Control_Resize(Editor2, 20, 410, W1-Rpos, 200)
Control_Resize(Btn_Paste, W1-(Rpos-40), 40, 100, 40)
Control_Resize(Btn_Clear, W1-(Rpos-40), 100, 100, 40)
Control_Resize(Btn_Build, W1-(Rpos-40), 200, 100, 40)
Control_Resize(Btn_Copy, W1-(Rpos-40), 410, 100, 40)
Control_Resize(Btn_Exit, W1-(Rpos-40), 600, 100, 40)
End Select
Loop Until Window_Event_Close(Window_Main, msg)
End
'Wait until window is closed:
Do
WaitEvent(Window_Main, msg)
Loop Until Window_Event_Close(Window_Main, msg)
'Delete font:
Control_DeleteFont(hFont)
End