• Welcome to PlanetSquires Forums.
 
Main Menu

Recent posts

#31
General Board / Re: Usage of Fixed Length Stri...
Last post by José Roca - March 14, 2024, 02:40:12 PM
> It is indeed hardly used at all and 2 instances I seen only in comments:

These are all unintentional errors likely caused by copying code from one part to another. It should be WSTRING * instead of STRING *

If it was still using random files, surely I would need fixed strings.
#32
Here is a simple Code example :

' use and include the libcl.bi library

#Include "libcl.bi"

' Initialize the library
cl_init()

' Open the Excel file
Dim handle As cl_handle = cl_open("path/to/your/excel/file.xlsx")

' Check if the file is opened successfully
If handle <> 0 Then

  ' Get the first sheet
  Dim sheet As cl_handle = cl_get_sheet(handle, 0)

  ' Get the total number of rows and columns in the sheet
  Dim rows As Integer = cl_get_rows(sheet)
  Dim cols As Integer = cl_get_cols(sheet)

  ' Print the data from the sheet
  For i As Integer = 0 To rows - 1
    For j As Integer = 0 To cols - 1
      Dim value As String = cl_get_cell(sheet, i, j)
      Print Using "#######"; j + 1; " : "; value;
    Next j
    Print
  Next i

  ' Close the sheet and the file
  cl_close_sheet(sheet)
  cl_close(handle)

Else
  Print "Error: Unable to open the file."
End If

' Clean up and uninitialize the library
cl_cleanup()
cl_uninit()

' Pause the program to view the output
Print "Press any key to continue..."
Sleep

 -l libcli.dll

' For example:
fbc your_program.bas -l libcli.dll
#33
Hello Peter do you are using an extern library Like libxl.dll  libcl.bi ?
Much Work to adept I think or use a Parser perhaps or write an own little freebasic example how to load a few amount of Data (my Idea I would prefer)... and then Look at more Help Here at the Board ;-) ? If I know more I will Tell you don't have tried working with Excel files

Good Luck, Frank
#34
Hi Peter,

Yes! You'll save an enormous amount of trouble if you save spreadsheets as CSV files.

A CSV file is a normal text file with, ahem, Comma-Separated Values. Each row in the spreadsheet is one line in the text file, with the fields separated by commas (optionally by TABs or something else). Text fields are enclosed in quotes, numbers are written as they stand. If the spreadsheet consists of one long column, the CSV will consist of one value per line, all the way down.

As for which kind of string to use, it depends on how the sheet was saved. If it was saved as UTF-16, then it's using wide characters, and CWSTRs are appropriate. If it was saved as UTF-8 or any of 20 or so other code pages, then it's using single-byte characters and regular STRINGs are right. Stick to one or the other.

Phil
#35
Good morning I have the solution was quite simple often WE are thinking too complicated lol

Used nehe 2 example.. If you Press a Keyboard Key the Hex value IS displayed

Solution Looks Like this one

CASE WM_KEYDOWN
         ' // Process keystrokes
           ' shows all keyboard codes :-)
            wkeystate = wParam AND &HFF ' Extract the key code
            PRINT "Last key pressed: 0x"; HEX(wkeystate)


'
########################################################################################
' Microsoft Windows
' File: CW_OGL_Nehe_02
' Contents: CWindow OpenGL - NeHe lesson 2
' Compiler: FreeBasic 32 & 64 bit
' Translated in 2017 by José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "GL/windows/glu.bi"
USING Afx

CONST GL_WINDOWWIDTH  = 600              ' Window width
CONST GL_WINDOWHEIGHT  = 400              ' Window height
CONST GL_WindowCaption = "NeHe Lesson 2"  ' Window caption

DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                          BYVAL hPrevInstance AS HINSTANCE, _
                          BYVAL szCmdLine AS ZSTRING PTR, _
                          BYVAL nCmdShow AS LONG) AS LONG

  END WinMain(GetModuleHandleW(NULL), NULL, COMMAND(), SW_NORMAL)

' // Forward declarations
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

' =======================================================================================
' OpenGL class
' =======================================================================================
TYPE COGL

  Private:
      m_hDC AS HDC      ' // Device context handle
      m_hRC AS HGLRC    ' // Rendering context handle
      m_hwnd AS HWND    ' // Window handle

  Public:
      DECLARE CONSTRUCTOR (BYVAL hwnd AS HWND, BYVAL nBitsPerPel AS LONG = 32, BYVAL cDepthBits AS LONG = 24)
      DECLARE DESTRUCTOR
      DECLARE SUB SetupScene (BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
      DECLARE SUB ResizeScene (BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
      DECLARE SUB RenderScene
      DECLARE SUB ProcessKeystrokes (BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM)
      DECLARE SUB ProcessMouse (BYVAL uMsg AS UINT, BYVAL wKeyState AS DWORD, BYVAL x AS LONG, BYVAL y AS LONG)
      DECLARE SUB Cleanup

END TYPE
' =======================================================================================

' ========================================================================================
' COGL constructor
' ========================================================================================
CONSTRUCTOR COGL (BYVAL hwnd AS HWND, BYVAL nBitsPerPel AS LONG = 32, BYVAL cDepthBits AS LONG = 24)

  DO  ' // Using a fake loop to avoid the use of GOTO or nested IFs/END IFs

      ' // Get the device context
      IF hwnd = NULL THEN EXIT DO
      m_hwnd = hwnd
      m_hDC = GetDC(m_hwnd)
      IF m_hDC = NULL THEN EXIT DO

      ' // Pixel format
      DIM pfd AS PIXELFORMATDESCRIPTOR
      pfd.nSize      = SIZEOF(PIXELFORMATDESCRIPTOR)
      pfd.nVersion  = 1
      pfd.dwFlags    = PFD_DRAW_TO_WINDOW OR PFD_SUPPORT_OPENGL OR PFD_DOUBLEBUFFER
      pfd.iPixelType = PFD_TYPE_RGBA
      pfd.cColorBits = nBitsPerPel
      pfd.cDepthBits = cDepthBits

      ' // Find a matching pixel format
      DIM pf AS LONG = ChoosePixelFormat(m_hDC, @pfd)
      IF pf = 0 THEN
        MessageBoxW hwnd, "Can't find a suitable pixel format", _
                    "Error", MB_OK OR MB_ICONEXCLAMATION
        EXIT DO
      END IF

      ' // Set the pixel format
      IF SetPixelFormat(m_hDC, pf, @pfd) = FALSE THEN
        MessageBoxW hwnd, "Can't set the pixel format", _
                    "Error", MB_OK OR MB_ICONEXCLAMATION
        EXIT DO
      END IF

      ' // Create a new OpenGL rendering context
      m_hRC = wglCreateContext(m_hDC)
      IF m_hRC = NULL THEN
        MessageBoxW hwnd, "Can't create an OpenGL rendering context", _
                    "Error", MB_OK OR MB_ICONEXCLAMATION
        EXIT DO
      END IF

      ' // Make it current
      IF wglMakeCurrent(m_hDC, m_hRC) = FALSE THEN
        MessageBoxW hwnd, "Can't activate the OpenGL rendering context", _
                    "Error", MB_OK OR MB_ICONEXCLAMATION
        EXIT DO
      END IF

      ' // Exit the fake loop
      EXIT DO
  LOOP

END CONSTRUCTOR
' ========================================================================================

' ========================================================================================
' COGL Destructor
' ========================================================================================
DESTRUCTOR COGL
  ' // Release the device and rendering contexts
  wglMakeCurrent m_hDC, NULL
  ' // Make the rendering context no longer current
  wglDeleteContext m_hRC
  ' // Release the device context
  ReleaseDC m_hwnd, m_hDC
END DESTRUCTOR
' ========================================================================================

' =======================================================================================
' All the setup goes here
' =======================================================================================
SUB COGL.SetupScene (BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)

  ' // Specify clear values for the color buffers
  glClearColor 0.0, 0.0, 0.0, 0.0
  ' // Specify the clear value for the depth buffer
  glClearDepth 1.0
  ' // Specify the value used for depth-buffer comparisons
  glDepthFunc GL_LESS
  ' // Enable depth comparisons and update the depth buffer
  glEnable GL_DEPTH_TEST
  ' // Select smooth shading
  glShadeModel GL_SMOOTH

END SUB
' =======================================================================================

' =======================================================================================
' Resize the scene
' =======================================================================================
SUB COGL.ResizeScene (BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)

  ' // Prevent divide by zero making height equal one
  IF nHeight = 0 THEN nHeight = 1
  ' // Reset the current viewport
  glViewport 0, 0, nWidth, nHeight
  ' // Select the projection matrix
  glMatrixMode GL_PROJECTION
  ' // Reset the projection matrix
  glLoadIdentity
  ' // Calculate the aspect ratio of the window
  gluPerspective 45.0, nWidth / nHeight, 0.1, 100.0
  ' // Select the model view matrix
  glMatrixMode GL_MODELVIEW
  ' // Reset the model view matrix
  glLoadIdentity

END SUB
' =======================================================================================

' =======================================================================================
' Draw the scene
' =======================================================================================
SUB COGL.RenderScene

  ' // Clear the screen buffer
  glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
  ' // Reset the view
  glLoadIdentity

  glTranslatef -1.5, 0.0, -6.0          ' Move left 1.5 units and into the screen

  glBegin GL_TRIANGLES                  ' Drawing using triangles
      glVertex3f  0.0, 1.0, 0.0          ' Top
      glVertex3f  1.0,-1.0, 0.0          ' Bottom right
      glVertex3f -1.0,-1.0, 0.0          ' Bottom left
  glEnd                                ' Finished drawing the triangle

  glTranslatef 3.0,0.0,0.0              ' Move right 3 units

  glBegin GL_QUADS                      ' Draw a quad
      glVertex3f -1.0, 1.0, 0.0          ' Top left
      glVertex3f  1.0, 1.0, 0.0          ' Top right
      glVertex3f  1.0,-1.0, 0.0          ' Bottom right
      glVertex3f -1.0,-1.0, 0.0          ' Bottom left
  glEnd                                ' Done drawing the quad

  ' // Exchange the front and back buffers
  SwapBuffers m_hdc

END SUB
' =======================================================================================

' =======================================================================================
' Processes keystrokes
' Parameters:
' * uMsg = The Windows message
' * wParam = Additional message information.
' * lParam = Additional message information.
' The contents of the wParam and lParam parameters depend on the value of the uMsg parameter.
' =======================================================================================
SUB COGL.ProcessKeystrokes (BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM)

  SELECT CASE uMsg
      CASE WM_KEYDOWN  ' // A nonsystem key has been pressed
        SELECT CASE LOWORD(wParam)
            CASE VK_ESCAPE
              ' // Send a message to close the application
              SendMessageW m_hwnd, WM_CLOSE, 0, 0
        END SELECT
  END SELECT

END SUB
' =======================================================================================

' =======================================================================================
' Processes mouse clicks and movement
' Parameters:
' * wMsg      = Windows message
' * wKeyState = Indicates whether various virtual keys are down.
'              MK_CONTROL    The CTRL key is down.
'              MK_LBUTTON    The left mouse button is down.
'              MK_MBUTTON    The middle mouse button is down.
'              MK_RBUTTON    The right mouse button is down.
'              MK_SHIFT      The SHIFT key is down.
'              MK_XBUTTON1  Windows 2000/XP: The first X button is down.
'              MK_XBUTTON2  Windows 2000/XP: The second X button is down.
' * x        = x-coordinate of the cursor
' * y        = y-coordinate of the cursor
' =======================================================================================
SUB COGL.ProcessMouse (BYVAL uMsg AS UINT, BYVAL wKeyState AS DWORD, BYVAL x AS LONG, BYVAL y AS LONG)

  SELECT CASE uMsg

      CASE WM_LBUTTONDOWN  ' // Left mouse button pressed
        ' // Put your code here

      CASE WM_LBUTTONUP  ' // Left mouse button releases
        ' // Put your code here

      CASE WM_MOUSEMOVE  ' // Mouse has been moved
        ' // Put your code here

      END SELECT

END SUB
' =======================================================================================

' =======================================================================================
' Cleanup
' =======================================================================================
SUB COGL.Cleanup

  ' ------------------------------------------------------------------------------------
  ' Insert your code here
  ' ------------------------------------------------------------------------------------

END SUB
' =======================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                  BYVAL hPrevInstance AS HINSTANCE, _
                  BYVAL szCmdLine AS ZSTRING PTR, _
                  BYVAL nCmdShow AS LONG) AS LONG

  ' // Set process DPI aware
  ' // The recommended way is to use a manifest file
  AfxSetProcessDPIAware

  ' // Creates the main window
  DIM pWindow AS CWindow
  ' -or- DIM pWindow AS CWindow = "MyClassName" (use the name that you wish)
  ' // Create the window
  DIM hwndMain AS HWND = pWindow.Create(NULL, GL_WindowCaption, @WndProc)
  ' // Don't erase the background
  pWindow.ClassStyle = CS_DBLCLKS
  ' // Use a black brush
  pWindow.Brush = CreateSolidBrush(BGR(0, 0, 0))
  ' // Sizes the window by setting the wanted width and height of its client area
  pWindow.SetClientSize(GL_WINDOWWIDTH, GL_WINDOWHEIGHT)
  ' // Centers the window
  pWindow.Center

  ' // Show the window
  ShowWindow hwndMain, nCmdShow
  UpdateWindow hwndMain
 
  ' // Message loop
  DIM uMsg AS tagMsg
  WHILE GetMessageW(@uMsg, NULL, 0, 0)
      TranslateMessage @uMsg
      DispatchMessageW @uMsg
  WEND

  FUNCTION = uMsg.wParam

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

  STATIC pCOGL AS COGL PTR  ' // Pointer to the COGL class
  DIM wkeystate as integer, action as integer
 
  SELECT CASE uMsg

      CASE WM_SYSCOMMAND
        ' // Disable the Windows screensaver
        IF (wParam AND &hFFF0) = SC_SCREENSAVE THEN EXIT FUNCTION
        ' // Close the window
        IF (wParam AND &hFFF0) = SC_CLOSE THEN
            SendMessageW hwnd, WM_CLOSE, 0, 0
            EXIT FUNCTION
        END IF

      CASE WM_CREATE
        ' // Initialize the new OpenGL window
        pCOGL = NEW COGL(hwnd)
        ' // Retrieve the coordinates of the window's client area
        DIM rc AS RECT
        GetClientRect hwnd, @rc
        ' // Set up the scene
        pCOGL->SetupScene rc.Right - rc.Left, rc.Bottom - rc.Top
        ' // Set the timer (using a timer to trigger redrawing allows a smoother rendering)
        SetTimer(hwnd, 1, 0, NULL)
        EXIT FUNCTION

        CASE WM_DESTROY
        ' // Kill the timer
        KillTimer(hwnd, 1)
        ' // Clean resources
        pCOGL->Cleanup
        ' // Delete the COGL class
        Delete pCOGL
        ' // Ends the application by sending a WM_QUIT message
        PostQuitMessage(0)
        EXIT FUNCTION

      CASE WM_TIMER
        ' // Render the scene
        pCOGL->RenderScene
        EXIT FUNCTION

      CASE WM_SIZE
        pCOGL->ResizeScene LOWORD(lParam), HIWORD(lParam)
        EXIT FUNCTION

      CASE WM_KEYDOWN
        ' // Process keystrokes
          ' shows all keyboard codes :-)
            wkeystate = wParam AND &HFF ' Extract the key code
            PRINT "Last key pressed: 0x"; HEX(wkeystate)
           
        pCOGL->ProcessKeystrokes uMsg, wParam, lParam
        EXIT FUNCTION

      CASE WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE
        ' // Process mouse movements
        pCOGL->ProcessMouse uMsg, wParam, LOWORD(lParam), HIWORD(lParam)
        EXIT FUNCTION

  END SELECT

  ' // Default processing of Windows messages
  FUNCTION = DefWindowProcW(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================
#36
Hi All

I need to be able to read an Excel file as a source for a long list of numbers into a Winfbx application.

It will be just one long column.

Would it be easier to let them save it in CSV?
As far as I understand, the CSV is almost like a normal text file.

Do we read a CSV the same as a normal input file?
Should I use Line Input with a CWSTR or are the variable is a CSV normal strings?

Thanks - Peter
#37
General Board / Re: Usage of Fixed Length Stri...
Last post by philbar - March 14, 2024, 03:23:16 AM
Quote from: Jeff Marshall on March 13, 2024, 08:22:34 PM
QuoteMany, many years ago, when I was working with the DOS operating system, I used it to work with random files.
I kind of miss that feature for working with some kinds of files; one motivation of several varied motivations for working on this old, probably nobody cares about feature.

I care. I work with a database consisting of gigabytes of Fortran-generated flat files with embedded b-trees. It is alive and well and being added to daily. In each record, the fields that are character type are fixed-length, space-padded strings. Byte arrays are an inconvenient substitute for a string type that exactly matches the data. I'd like to do the occasional new programs with FB, as WinFBE makes it easy to create attractive GUI interfaces.

Maybe I'm a dinosaur. Incidentally, I've been following the discussion of this on the FB forum. It sounded so easy at first...
#38
General Board / Re: Usage of Fixed Length Stri...
Last post by Jeff Marshall - March 13, 2024, 08:22:34 PM
Thank you for the feedback.

Quote from: José Roca on March 13, 2024, 06:28:08 AMI don't remember ever using AS STRING * with FreeBasic because all my WinFBX code is unicode.
It is indeed hardly used at all and 2 instances I seen only in comments:
./Afx/AfxWin.inc:958:
'   DIM wszInitialDir AS STRING * 260 = CURDIR

./Afx/AfxWin.inc:1061:
'   DIM wszInitialDir AS STRING * 260 = CURDIR

./Examples/Sample_Projects/DShow_PlayClip/DShow_PlayClip.bas:168:
DIM wszInitialDir AS STRING * MAX_PATH = CURDIR

./TLB_100/TLB_100.bas:135:
DIM wszInitialDir AS STRING * 260 = CURDIR

./TLB_100/TLB_100.bas:173:
DIM wszInitialDir AS STRING * 260 = CURDIR

QuoteMany, many years ago, when I was working with the DOS operating system, I used it to work with random files.
I kind of miss that feature for working with some kinds of files; one motivation of several varied motivations for working on this old, probably nobody cares about feature.
#39
Yes thanks Its a good example i have tested already but my question directed more to General  Keyboard Codes in OpenGL Modu

Something below
Case WM_KEYDOWN
...
fictive code
Print "last key pressed"
If lastkey = 1 then
Print lastkey + "  = 0x" hex(lastkey)
End If

#macro keydown
Case 27 : ' No Action ' escape key
Case 32 : ' No Action  ' space key
#endmacro


'sorry, my mistake, I know your nehe 8 example 'already yes it's a good one but my intention was
'to print the keyboard key codes :-)

'something like that in openGL and appears on 'console too

'

glColor4f 1.0, 1.0, 1.0, 0.5
dim mylastkey as integer

if mylastkey ' = 1 then
  print mylastkey " = 0x" hex(mylastkey)
else
  print "(none)"
end if

' my name
f 70=0x46
r 82=0x52
a 65=0x41
n 78=0x4e
k 75=0x4B


I have tried to built in nehe example 10 but failed
#40
Better take another example like the 08, which processes several keys:

' =======================================================================================
' Processes keystrokes
' Parameters:
' * uMsg = The Windows message
' * wParam = Additional message information.
' * lParam = Additional message information.
' The contents of the wParam and lParam parameters depend on the value of the uMsg parameter.
' =======================================================================================
SUB COGL.ProcessKeystrokes (BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM)

   STATIC AS BOOLEAN lp, fp, light

   SELECT CASE uMsg
      CASE WM_KEYDOWN   ' // A nonsystem key has been pressed
         SELECT CASE LOWORD(wParam)
            CASE VK_ESCAPE
               ' // Send a message to close the application
               SendMessageW m_hwnd, WM_CLOSE, 0, 0
            CASE VK_B
               blend = NOT blend
               IF blend = FALSE THEN
                  glEnable GL_BLEND
                  glDisable GL_DEPTH_TEST
               ELSE
                  glDisable GL_BLEND
                  glEnable GL_DEPTH_TEST
               END IF
            CASE VK_L
               light = NOT light
               IF light = FALSE THEN glDisable GL_LIGHTING ELSE glEnable GL_LIGHTING
            CASE VK_F
               filter += 1
               IF filter > 2 THEN filter = 0
            CASE VK_PRIOR   ' // page up
               zoom -= 0.02
            CASE VK_NEXT   ' // page down
               zoom += 0.02
            CASE VK_UP
               xspeed -= 0.01
            CASE VK_DOWN
               xspeed += 0.01
            CASE VK_LEFT
               yspeed -= 0.01
            CASE VK_RIGHT
               yspeed += 0.01
         END SELECT
   END SELECT

END SUB
' =======================================================================================