Author Topic: Read & Print the Type from your bas source  (Read 3785 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Read & Print the Type from your bas source
« on: January 09, 2022, 04:45:11 pm »
Proof of concept, proved!
Code: QB64: [Select]
  1. _Title "Read Type test" 'b+ 2022-01-09
  2.  
  3. Type ButtonData
  4.     Caption As String
  5.     Department As String
  6.     Group As String
  7.     Price As Integer
  8.     TaxRate As Integer
  9.     Printer As Integer
  10.     Colour_Red As Integer
  11.     Colour_Green As Integer
  12.     Colour_Blue As Integer
  13.  
  14. Print myType$("Read Type test.bas")
  15.  
  16.  
  17. Function myType$ (file$) ' for proof of concept assuming one type to get
  18.     If _FileExists(file$) Then
  19.         Open file$ For Input As #1
  20.         While Not EOF(1)
  21.             Line Input #1, fl$
  22.             If Left$(fl$, 4) = "Type" Then
  23.                 While Left$(fl$, 8) <> "End Type"
  24.                     Line Input #1, fl$
  25.                     If b$ = "" Then
  26.                         b$ = _Trim$(Mid$(fl$, 1, InStr(fl$, " A"))) ' hmmm does trim$ do tabs?
  27.                     Else
  28.                         b$ = b$ + Chr$(10) + _Trim$(Mid$(fl$, 1, InStr(fl$, " A")))
  29.                     End If
  30.                 Wend
  31.                 myType$ = b$
  32.                 Close #1
  33.                 Exit Function
  34.             End If
  35.         Wend
  36.     End If
  37.  

Remember to save this to disk before trying.

edit: add close #1
edit: exit function when you got what you came for
« Last Edit: January 09, 2022, 04:53:36 pm by bplus »