QButton
QButton Example

QButton Examples

  '-- A drag button

  DIM Form AS QForm

  DIM Button AS QButton

  SUB MouseDown

      Button.StartDrag

      SHOWMESSAGE STR$(Button.Left)+", "+STR$(Button.Top)

  END SUB

  Button.Parent = Form

  Button.OnMouseDown = MouseDown

  Form.ShowModal


QClipboard
QClipboard Example

ClipBoard Examples

ClipBoard.Open

PRINT ClipBoard.Text

ClipBoard.Close


QPrinter
QPrinter Example

Printer Examples

DECLARE SUB ButtonClick

SUB ComboBoxChange(Sender AS QComboBox)

  Printer.PrinterIndex = Sender.ItemIndex '- Change default printer

END SUB

DIM Font AS QFont

    Font.Color = &HFF0000

    Font.Name = "Arial"

    Font.Size = 20

DIM Bitmap AS QBitmap

Bitmap.BMP = "rapidq.bmp"

CREATE Form AS QForm

  CREATE ComboBox AS QComboBox

    Left = 5

    Top = 5

    Width = 150

    OnChange = ComboBoxChange

  END CREATE

  CREATE Button AS QButton

    Caption = "&Print"

    Top = 3

    Left = 180

    OnClick = ButtonClick

  END CREATE

  CREATE GroupBox AS QGroupBox

    Caption = "Print Preview..."

    Top = 35

    Width = Form.ClientWidth

  END CREATE

  Center

END CREATE

FOR I = 0 TO Printer.PrintersCount-1

  ComboBox.AddItems(Printer.Printers(I))    '-- Add printer list to combobox

NEXT

ComboBox.ItemIndex = Printer.PrinterIndex

Form.ShowModal

SUB ButtonClick

  Printer.Orientation = 1   ' Landscape

  Printer.BeginDoc

  Printer.TextOut(1000,1000,"Hi World!",0,-1)

  Printer.Font = Font

  Printer.TextOut(10,10,"Does this print?",0,-1)

  Printer.Line(10,10,500,500,0)

  Printer.EndDoc

END SUB

QCanvas Examples

'  Pixel by pixel credit scroller for Rapid-Q by William Yu

DIM Canvas AS QCanvas

DIM Form AS QForm

DIM Timer1 AS QTimer

DIM Font AS QFont

DIM Y AS INTEGER

    Y = -20

SUB Resize

  Canvas.Height = Form.ClientHeight

  Canvas.Width = Form.ClientWidth

END SUB

SUB Paint

  Canvas.Textout (65,Y-30,"Beware the power of Rapid-Q!", &H00FF00, 0)

  Canvas.Textout (30,Y,"Credit Scroller written in Rapid-Q by William Yu", &HFFFFFF, 0)

END SUB

SUB TimerOver

  Timer1.Interval = 1  '' Can't go any lower!

  Y = Y + 1            '' Pixel by pixel!

  Paint

END SUB

Form.Width = 400

Form.Height = 200

Form.Center

Form.Color = 0

Font.Name = "Arial"

Font.Size = 12

Font.Color = &H00FF00

Canvas.Parent = Form

Canvas.Font = Font

Canvas.Color = 0

Canvas.OnPaint = Paint

Timer1.Interval = 1

Timer1.OnTimer = TimerOver

Form.Onresize = Resize

Form.ShowModal


QCheckBox
QCheckBox Example

QCheckbox Examples

  DIM Form AS QForm

  DIM Checkbox as QCheckBox

  SUB Check

    IF CheckBox.Checked THEN

       SHOWMESSAGE "Checked!"

    END IF

  END SUB

  CheckBox.Parent = Form

  CheckBox.OnClick = Check

  Form.ShowModal


QComboBox
QComboBox Example

QCombobox Examples

  DIM Form AS QForm

  DIM ComboBox AS QComboBox

  SUB ItemChanged

    PRINT ComboBox.Item(ItemIndex)

  END SUB

  ComboBox.Parent = Form

  ComboBox.OnChange = ItemChanged

  ComboBox.AddItems "1. Apples", "2. Oranges", "3. Bananas"

  Form.ShowModal


QCollBtn
QCoolBtn Example

QCoolbtn Examples

  '-- An example of toggle buttons (via GroupIndex)

  CONST False = 0: CONST True = 1

  DIM Form AS QForm

  DIM Cool1 AS QCoolbtn

  DIM Cool2 AS QCoolbtn

  Cool1.Parent = Form

  Cool1.GroupIndex = 1       '' Must be > 0

  Cool1.Down = True          '' Button initially down

  Cool2.Parent = Form

  Cool2.GroupIndex = 1       '' Same group as Cool1

  Cool2.Left = 40

  Form.ShowModal


QDirTree
QDirTree Example

QDirTree Examples

'' A Directory Tree like Windows Explorer.

'' QDIRTREE Component courtesy of Markus Stephany.

'' I took out removable drives because it doesn't work properly.

'' So you won't be able to view your floppy disk drives.  CD-ROM drives

'' are fine, as far as I know...

$TYPECHECK ON

DECLARE SUB ChangeDirectory

CREATE Form AS QForm

  Caption = "Directory Tree"

  Center

  CREATE DirTree AS QDirTree

    InitialDir = CURDIR$

    Width = Form.ClientWidth

    Height = Form.ClientHeight

    OnChange = ChangeDirectory

  END CREATE

  ShowModal

END CREATE

SUB ChangeDirectory

  ShowMessage DirTree.Directory

END SUB


QEdit
QEdit Example

QEdit Input Masks

 !	If a ! character appears in the mask, optional characters are represented

        in the EditText as leading blanks. If a ! character is not present, optional

        characters are represented in the EditText as trailing blanks.

 >	If a > character appears in the mask, all characters that follow are in

        uppercase until the end of the mask or until a < character is encountered.

 <      If a < character appears in the mask, all characters that follow are in

        lowercase until the end of the mask or until a > character is encountered.

 <>     If these two characters appear together in a mask, no case checking is

        done and the data is formatted with the case the user uses to enter the data.

 \	The character that follows a \ character is a literal character. Use this

        character to use any of the mask special characters as a literal in the data.

 L	The L character requires an alphabetic character only in this position.

        For the US, this is A-Z, a-z.

 l	The l character permits only an alphabetic character in this position, but

        doesn't require it.

 A	The A character requires an alphanumeric character only in this position.

        For the US, this is A-Z, a-z, 0-9.

 a	The a character permits an alphanumeric character in this position, but

        doesn't require it.

 C	The C character requires an arbitrary character in this position.

 c	The c character permits an arbitrary character in this position, but

        doesn't require it.

 0	The 0 character requires a numeric character only in this position.

 9	The 9 character permits a numeric character in this position, but doesn't

        require it.

 #	The # character permits a numeric character or a plus or minus sign in

        this position, but doesn't require it.

 :	The : character is used to separate hours, minutes, and seconds in times.

        If the character that separates hours, minutes, and seconds is different

        in the regional settings of the Control Panel utility on your computer

        system, that character is used instead.

 /	The / character is used to separate months, days, and years in dates.

        If the character that separates months, days, and years is different

        in the regional settings of the Control Panel utility on your computer

        system, that character is used instead.

 ;	The ; character is used to separate the three fields of the mask.

 _	The _ character automatically inserts spaces into the text. When the

        user enters characters in the field, the cursor skips the _ character.

QEdit Examples

  DIM Form AS QForm

  DIM Edit1 AS QEdit

  Edit1.Parent = Form

  Edit1.Text = "Hello"   '' Set as default text

  Form.ShowModal


QFileListBox
QFileListBox Example

QFileListBox Examples

'' Simple Application Launcher

'' How to use the File List Box as a Directory List Box in Rapid-Q

$INCLUDE "RAPIDQ.INC"

DECLARE SUB ChangeDirectories

DECLARE SUB ExecuteApplication

DECLARE SUB ResizeForm

CREATE Form AS QForm

  Height = 300

  Width = 450

  CREATE DirList AS QFileListBox     '' Can double as a Directory list box

   ShowIcons = True

   Mask = "*.*"

   AddFileType(ftDirectory)          '' Add Directories

   DelFileType(ftNormal)             '' Remove files (see RAPIDQ.INC for values)

   OnDblClick = ChangeDirectories

   Height = Form.ClientHeight

   Width = 200

  END CREATE

  CREATE EXEList AS QFileListBox

   ShowIcons = True

   Mask = "*.EXE"

   OnDblClick = ExecuteApplication

   Left = 215

   Height = Form.ClientHeight

   Width = 225

  END CREATE

  Center

  Caption = DirList.Directory

  OnResize = ResizeForm

  ShowModal

END CREATE

SUB ChangeDirectories

  ChDir(DirList.Item(DirList.ItemIndex) - "[" - "]")

  DirList.Directory = CurDir$:  EXEList.Directory = CurDir$

  Form.Caption = CurDir$

END SUB

SUB ExecuteApplication

  RUN EXEList.FileName    ' Non-Blocking

'  SHELL EXEList.FileName  ' Blocks, until program terminates

                           ' Becareful running 16-bit applications

END SUB

SUB ResizeForm

  DirList.Height = Form.ClientHeight

  EXEList.Height = Form.ClientHeight

  EXEList.Width = Form.ClientWidth - 215

END SUB


QFileStream
QFileStream Example

QFileStream Examples

  $INCLUDE "RAPIDQ.INC"

  DIM File AS QFileStream

  File.Open("test.bas", fmOpenRead)

  File.ReadStr(S$, File.Size)         '' Read entire file

  PRINT S$                            '' print it

  File.Close

'------------------------------------------------------

  $INCLUDE "RAPIDQ.INC"

  TYPE MyType

      Name AS STRING*30

      Phone AS STRING*8

      Age AS INTEGER

  END TYPE

  DIM Person AS MyType

      Person.Name = "Joe"

      Person.Phone = "555-5555"

  DIM File AS QFileStream

      File.Open("test", fmCreate)

      File.WriteUDT(Address)


QFont
QFont Example

QFont Examples

  $INCLUDE "RAPIDQ.INC"

  DIM Font AS QFONT

  DIM Label AS QLABEL

  Font.Name = "Arial"

  Font.AddStyles(fsBold, fsItalic)

  Label.Font = Font      '' Assign font values


QFontDialog
QFontDialog Example

QFontDialog Examples

  '-- Simple demo

  DIM FontDialog AS QFontDialog

  DIM Font AS QFont

      Font.Name = "Arial"

  FontDialog.GetFont(Font)

  IF FontDialog.Execute THEN

    ShowMessage "You selected "+FontDialog.Name

    FontDialog.SetFont(Font)

  END IF

QForm Examples

  DIM Form AS QForm

  DIM Button AS QBUTTON

  Button.Parent = Form     '' Add button to form container

  Form.Center

  Form.Caption = "Hello world!"

  IF Form.ShowModal THEN

    PRINT "Return result is TRUE"

  ELSE

    PRINT "Return result is FALSE"

  END IF


QGauge
QGauge Example

QGauge Examples

$INCLUDE "RAPIDQ.INC"

CREATE Form AS QForm

  Center

  CREATE Gauge AS QGauge

    Position = 20

    Kind = gkPie

  END CREATE

  ShowModal

END CREATE


QGlassFrame
QGlassFrame Example

QGlassFrame Examples

$INCLUDE "RAPIDQ.INC"

CREATE Form AS QForm

  Caption = "Transparent Form"

  Center

  CREATE GlassFrame AS QGlassFrame

      Align = alClient

  END CREATE

  ShowModal

END CREATE

'------- Weird transparency color error

$INCLUDE "RAPIDQ.INC"

CREATE Form AS QForm

  Caption = "Transparent Form"

  Center

  CREATE GlassFrame AS QGlassFrame

      Align = alClient

      TransparentColor = &HFF0000

  END CREATE

  Show

END CREATE

'-- I don't know what's wrong, but doing this seems to

'-- work better than using ShowModal when changing colors

DO

    DoEvents

LOOP UNTIL Form.Visible = 0


QGroupBox
QGroupBox Example

QGroupBox Examples

CREATE Form AS QForm

  CREATE GroupBox AS QGroupBox

    Caption = " Group Box "

    Left = 100

    CREATE Button AS QButton

      Caption = "Button"

    END CREATE

  END CREATE

  Center

  ShowModal

END CREATE


QHeader
QHeader Example

QHeader Examples

$TYPECHECK ON

$INCLUDE "RAPIDQ.INC"

DECLARE SUB DrawSection (Index AS INTEGER, Pressed AS INTEGER, Rect AS QRECT, Sender AS QHEADER)

DECLARE SUB SectionTrack (Index AS INTEGER, Width AS INTEGER, State AS INTEGER, Sender AS QHEADER)

CREATE Form AS QFORM

    Caption = "QHeader example"

    Center

    CREATE Header AS QHEADER

        AddSections "1", "2", "3"

        Sections(1).AllowClick = FALSE

        Sections(0).Style = hsOwnerDraw

        Sections(0).Width = 100

        Sections(1).Style = hsOwnerDraw

        Sections(2).Style = hsOwnerDraw

        OnDrawSection = DrawSection

        OnSectionTrack = SectionTrack

    END CREATE

    CREATE ListBox1 AS QLISTBOX

        Align = alLeft

        Width = 100

        AddItems "1. Rapid-Q", "2. Taxes"

    END CREATE

    CREATE StatusBar AS QSTATUSBAR

        SimplePanel = TRUE

        SimpleText = "Not moving"

    END CREATE

    ShowModal

END CREATE

SUB DrawSection (Index AS INTEGER, Pressed AS INTEGER, Rect AS QRECT, Sender AS QHEADER)

    Sender.TextOut(Rect.Left+5,Rect.Top+1, STR$(Index+1), &HFF0000, -1)

    SELECT CASE Index

        CASE 0

            Sender.FillRect(Rect.Left+20,Rect.Top+2,Rect.Right-20,Rect.Bottom-2, &H00FF00)

        CASE 1

            Sender.Circle(Rect.Left+20,Rect.Top+2,Rect.Right-20,Rect.Bottom-2, &HFF, &HFF)

        CASE 2

    END SELECT

END SUB

SUB SectionTrack (Index AS INTEGER, Width AS INTEGER, State AS INTEGER, Sender AS QHEADER)

    StatusBar.SimpleText = "Moving "+STR$(Width)

    SELECT CASE Index

        CASE 0

            ListBox1.Width = Width

    END SELECT

END SUB


QImage

QImage Examples

  '-- How to use a resource file

  CONST False = 0

  CONST True = 1

  $RESOURCE RES_BMP1 AS "C:\WINDOWS\CLOUDS.BMP"

  DIM Form AS QForm

  DIM Image AS QImage

  Image.Parent = Form

  Image.Autosize = True

  Image.BMPHandle = RES_BMP1

  Form.ShowModal


QImageList
QImageList Example

QImageList Examples

' Imagelist demo

$resource bmp_handle as "nolight.bmp"

$resource ico_handle as "close.ico"

DIM ImageList AS QImageList

DIM Form AS QForm

DIM Button AS QButton

ImageList.Width = 9

ImageList.Height = 17

ImageList.AddBMPHandle bmp_handle,0

'ImageList.AddBMPFile "nolight.bmp", 0

ImageList.AddICOHandle ico_handle

'ImageList.AddICOFile "close.ico"

Button.Parent = Form

Button.BMP = Imagelist.GetBMP(0)

Form.Icon = ImageList.GetICO(1)

Form.Showmodal


QLabel
QLabel Example

QLabel Examples

  DIM Form AS QForm

  DIM Label1 AS QLabel

  Label1.Parent = Form

  Label1.Text = "Hello"

  Form.ShowModal

'--------------------------------------------------------

  ' Note that rotated labels only work with true type

  ' fonts, such as Arial and Courier New

  DIM Form AS QForm

  DIM Label1 AS QLabel

  DIM Font AS QFont

  Font.Name = "Arial"

  Label1.Parent = Form

  Label1.Font = Font

  Label1.Text = "Hello"

  Label1.Angle = 45

  Form.ShowModal


QListBox
QListBox Example

QListbox Examples

  DIM Form AS QForm

  DIM ListBox AS QListBox

  ListBox.Parent = Form

  ListBox.AddItems "1. Apples", "2. Oranges", "3. Bananas"

  ListBox.DelItems 1,2       '' Deletes Oranges and Bananas

  ListBox.Item(0) = "1. Strawberries"   '-- Change the first item

  Form.ShowModal


QListView
QListView Example

QListView Examples

' Simple .ZIP viewer (doesn't extract or anything useful like that).

' You're free to modify and distribute the code without restrictions.

' Demonstrates QOpenDialog, QFileStream, QListView, QMainMenu, QMenuItem

'              and QImageList.

$APPTYPE GUI

$TYPECHECK ON

$INCLUDE "RAPIDQ.INC"

$RESOURCE ICO_ZIP AS "ZIP.ICO"

$RESOURCE ICO_APP AS "APP.ICO"

DECLARE SUB ZipView (ZIPFile AS STRING)

DECLARE SUB FormResize

DECLARE SUB OpenClick

DECLARE SUB ExitClick

DECLARE SUB IconClick

DECLARE SUB SmallIconClick

DECLARE SUB ReportClick

DECLARE SUB ItemDblClick

CONST SIG = &H04034B50         ' ZIP Signature/ID

TYPE ZFHeader

  Signature AS LONG

  Version AS WORD

  GPBFlag AS WORD              ' ?

  Compress AS WORD             ' Compression types

  DateTime AS LONG             ' Packed format

  CRC32 AS LONG

  CSize AS LONG                ' Compressed size

  USize AS LONG                ' Uncompressed size

  FileNameLen AS LONG

END TYPE

TYPE PackedDateType            ' I think this is it:

  Year AS SHORT                ' 7 bits

  Month AS BYTE                ' 4 bits

  Day AS BYTE                  ' 5 bits

  Hour AS BYTE                 ' 5 bits

  Minute AS BYTE               ' 6 bits

  Secs AS BYTE                 ' 5 bits

END TYPE                       ' Total = 32 bits

DIM CompType(0 TO 9) AS STRING

    CompType(0) = "Stored"

    CompType(1) = "Shrunk"

    CompType(2) = "Reduced1"

    CompType(3) = "Reduced2"

    CompType(4) = "Reduced3"

    CompType(5) = "Reduced4"

    CompType(6) = "Imploded"

    CompType(7) = "Defalted"

    CompType(8) = "DeflatN"      '' Could be DeflatX as well...

    CompType(9) = "DeflatX"

DIM OpenItem AS QMenuItem

    OpenItem.Caption = "&Open"

    OpenItem.OnClick = OpenClick

DIM BreakItem AS QMenuItem

    BreakItem.Caption = "-"

DIM ExitItem AS QMenuItem

    ExitItem.Caption = "E&xit"

    ExitItem.OnClick = ExitClick

DIM IconItem AS QMenuItem

    IconItem.Caption = "vs&Icon"

    IconItem.RadioItem = True

    IconItem.OnClick = IconClick

DIM SmallIconItem AS QMenuItem

    SmallIconItem.Caption = "vs&SmallIcon"

    SmallIconItem.RadioItem = True

    SmallIconItem.OnClick = SmallIconClick

DIM ReportItem AS QMenuItem

    ReportItem.Caption = "vs&Report"

    ReportItem.RadioItem = True

    ReportItem.Checked = True

    ReportItem.OnClick = ReportClick

DIM FileMenu AS QMenuItem

    FileMenu.Caption = "&File"

    FileMenu.AddItems OpenItem, BreakItem, ExitItem

DIM ViewMenu AS QMenuItem

    ViewMenu.Caption = "&View"

    ViewMenu.AddItems IconItem, SmallIconItem, ReportItem

DIM ImageList1 AS QImageList

    ImageList1.Height = 32

    ImageList1.Width = 32

    ImageList1.AddICOHandle ICO_APP

    ImageList1.AddICOHandle ICO_ZIP

DIM ImageList2 AS QImageList            ' Scale 16x16

    ImageList2.Height = 16

    ImageList2.Width = 16

    ImageList2.AddICOHandle ICO_APP

    ImageList2.AddICOHandle ICO_ZIP

CREATE Form AS QForm

  ICOHandle = ICO_ZIP

  Center

  OnResize = FormResize

  Height = 330

  Width = 525

  Caption = "Simple .ZIP Viewer for Rapid-Q"

  CREATE MainMenu AS QMainMenu

    AddItems FileMenu, ViewMenu

  END CREATE

  CREATE ListView AS QListView

    Width = Form.ClientWidth

    Height = Form.ClientHeight

    SmallImages = ImageList2

    LargeImages = ImageList1

    ViewStyle = vsReport

    AddColumns "FileName","Length","Method","Size","Rate","Date","Time","CRC-32"

    Column(0).Width = 200

    Column(4).Width = 40

    Column(5).Width = 70

    Column(7).Width = 70

    OnDblClick = ItemDblClick

  END CREATE

  ShowModal

END CREATE

'------------------------------------------------------------------

SUB ZipView (ZIPFile AS STRING)

  DIM Hdr      AS ZFHeader

  DIM ZF       AS QFileStream

  DIM PD       AS PackedDateType

  DIM FileName AS STRING

  DIM Index    AS INTEGER

  IF ZF.Open(ZIPFile, fmOpenRead) = False THEN

    ShowMessage("Problem with reading "+ZIPFile)

    EXIT SUB

  END IF

  ListView.Clear

  Hdr.Signature = ZF.ReadNum(4)

  Index = 0

  WHILE Hdr.Signature = SIG

    Hdr.Version  = ZF.ReadNum(2)

    Hdr.GPBFlag  = ZF.ReadNum(2)

    Hdr.Compress = ZF.ReadNum(2)

    Hdr.DateTime = ZF.ReadNum(4)

    Hdr.CRC32 = ZF.ReadNum(4)

    Hdr.CSize = ZF.ReadNum(4)

    Hdr.USize = ZF.ReadNum(4)

    Hdr.FileNameLen = ZF.ReadNum(4)

    FileName = ZF.ReadStr(Hdr.FileNameLen)

    PD.Year = ((Hdr.DateTime SHR 25) AND &H7F) + 1980

    PD.Month = (Hdr.DateTime SHR 21) AND &H0F

    PD.Day = (Hdr.DateTime SHR 16) AND &H1F

    PD.Hour = (Hdr.DateTime SHR 11) AND &H1F

    PD.Minute = (Hdr.DateTime SHR 5) AND &H3F

    PD.Secs = Hdr.DateTime AND &H1F

    ListView.AddItems FileName

    IF INSTR(UCASE$(FileName), ".ZIP") THEN

      ListView.Item(Index).ImageIndex = 1

    END IF

    ListView.AddSubItem Index, STR$(Hdr.USize)

    ListView.AddSubItem Index, CompType(Hdr.Compress)

    ListView.AddSubItem Index, STR$(Hdr.CSize)

    IF Hdr.USize = 0 THEN

      ListView.AddSubItem Index, "----"

    ELSE

      ListView.AddSubItem Index, STR$(INT((Hdr.USize - Hdr.CSize) / Hdr.USize * 100))+"%"

    END IF

    ListView.AddSubItem Index, STR$(PD.Month)+"-"+STR$(PD.Day)+"-"+STR$(PD.Year)

    ListView.AddSubItem Index, STR$(PD.Hour)+":"+STR$(PD.Minute)

    ListView.AddSubItem Index, LCASE$(HEX$(Hdr.CRC32))

    ZF.Seek(Hdr.CSize, soFromCurrent)

    Hdr.Signature = ZF.ReadNum(4)

    Index = Index + 1

  WEND

  IF Index = 0 THEN

     '-- Likely not a .ZIP file

     ShowMessage(ZIPFile+" is not a valid ZIP file!")

  END IF

END SUB

SUB OpenClick

  DIM OpenDialog AS QOpenDialog

  OpenDialog.InitialDir = CurDir$

  OpenDialog.Filter = "ZIP Files (*.zip)|*.zip|All Files (*.*)|*.*"

  IF OpenDialog.Execute THEN

    ZipView(OpenDialog.FileName)

  END IF

END SUB

SUB ExitClick

  Form.Close

END SUB

SUB FormResize

  ListView.Height = Form.ClientHeight

  ListView.Width = Form.ClientWidth

END SUB

SUB IconClick

  IconItem.Checked = True

  ListView.ViewStyle = vsIcon

END SUB

SUB SmallIconClick

  SmallIconItem.Checked = True

  ListView.ViewStyle = vsSmallIcon

END SUB

SUB ReportClick

  ReportItem.Checked = True

  ListView.ViewStyle = vsReport

END SUB

SUB ItemDblClick

  IF ListView.ItemIndex >= 0 THEN

    ShowMessage("Can't extract "+ ListView.Item(ListView.ItemIndex).Caption);

  END IF

END SUB


QMainMenu
QMainMenu Example

QMainMenu Examples

  DIM Form AS QForm

  DIM MainMenu AS QMainMenu

  DIM Item1 AS QMenuItem

  Item1.Caption = "&File"

  MainMenu.AddItems Item1

  MainMenu.Parent = Form

  Form.ShowModal


QMemoryStream
QMemoryStream Example

QMemoryStream Examples

  DIM Mem AS QMemoryStream

  S$ = "Hello world!"

  Mem.WriteStr(S$, LEN(S$))

  Mem.Position = 0

  S$ = Mem.ReadStr(LEN(S$))

  PRINT S$                            '' print it

  Mem.Close

'------------------------------------------------------

  TYPE MyType

      Name AS STRING*30

      Phone AS STRING*8

      Age AS INTEGER

  END TYPE

  DIM Person AS MyType

      Person.Name = "Joe"

      Person.Phone = "555-5555"

  DIM Mem AS QMemoryStream

      Mem.WriteUDT(Address)


QMenuItem
QMenuItem Example

QMenuItem Examples

  DIM Form AS QForm

  DIM MainMenu AS QMainMenu

  DIM Item1 AS QMenuItem

  MainMenu.Parent = Form

  Item1.Caption = "&File"

  MainMenu.AddItems Item1

  Form.ShowModal


QMySQL
QMySQL Example

QMySQL Examples

' Sorry for lack of documentation, still a work in progress...

' This simply checks that you have a working MySQL server and lets you

' view some database fields.

$TYPECHECK ON

$INCLUDE "RAPIDQ.INC"

DECLARE SUB Button1Click (Sender AS QBUTTON)

DECLARE SUB DBListBoxClick (Sender AS QLISTBOX)

DECLARE SUB TableListBoxClick (Sender AS QLISTBOX)

DECLARE SUB SQLFormResize (Sender AS QFORM)

DIM Font AS QFONT

    Font.Name = "Courier"

DIM MySQL AS QMYSQL

    CREATE SQLForm AS QFORM

        Caption = "Connected"

        Width = 330

        Height = 300

        Center

        CREATE DBLabel AS QLABEL

            Caption = "Select a database:"

        END CREATE

        CREATE DBListBox AS QLISTBOX

            Top = 20

            Width = 150

            Height = 100

            OnClick = DBListBoxClick

        END CREATE

        CREATE TableListBox AS QLISTBOX

            Top = 20

            Left = 165

            Width = 150

            Height = 100

            OnClick = TableListBoxClick

        END CREATE

        CREATE FieldEdit AS QRICHEDIT

            Top = 130

            Width = SQLForm.ClientWidth

            Height = SQLForm.ClientHeight-130

            ReadOnly = TRUE

            WordWrap = FALSE

            PlainText = TRUE

            Font = Font

            ScrollBars = ssBoth

        END CREATE

        CREATE Grid AS QSTRINGGRID

            Top = 130

            Width = SQLForm.ClientWidth

            Height = SQLForm.ClientHeight-130

            AddOptions(goEditing)

        END CREATE

        OnResize = SQLFormResize

    END CREATE

CREATE Form AS QFORM

    Caption = "SQL Demo"

    Width = 230

    Height = 174

    Center

    CREATE Label1 AS QLABEL

        Caption = "Host:"

        Left = 44

        Top = 23

    END CREATE

    CREATE Label2 AS QLABEL

        Caption = "User name:"

        Left = 16

        Top = 50

        Width = 57

    END CREATE

    CREATE Label3 AS QLABEL

        Caption = "Password:"

        Left = 21

        Top = 79

        Width = 54

    END CREATE

    CREATE Edit1 AS QEDIT

        Text = ""

        Left = 83

        Top = 18

    END CREATE

    CREATE Edit2 AS QEDIT

        Text = ""

        Left = 83

        Top = 46

    END CREATE

    CREATE Edit3 AS QEDIT

        Text = ""

        Left = 83

        Top = 74

    END CREATE

    CREATE Button1 AS QBUTTON

        Caption = "&Ok"

        Left = 32

        Top = 112

        Kind = 1

        Default = 1

        NumBMPs = 2

        OnClick = Button1Click

    END CREATE

    CREATE Button2 AS QBUTTON

        Caption = "E&xit"

        Left = 118

        Top = 112

        Kind = 6

        NumBMPs = 2

    END CREATE

    ShowModal

END CREATE

SUB Button1Click

    DIM I AS INTEGER

    IF MySQL.Connect(Edit1.Text, Edit2.Text, Edit3.Text) = 0 THEN

       ShowMessage("Failed to connect to MySQL Server")

       EXIT SUB

    END IF

    FOR I = 0 TO MySQL.DBCount-1

        DBListBox.AddItems(MySQL.DB(I))

    NEXT

    SQLForm.ShowModal

    SUB DBListBoxClick (Sender AS QLISTBOX)

        IF Sender.ItemIndex < 0 THEN EXIT SUB

        IF MySQL.SelectDB(Sender.Item(Sender.ItemIndex)) = 0 THEN

            ShowMessage("Could not open "+Sender.Item(Sender.ItemIndex))

            EXIT SUB

        END IF

        TableListBox.Clear

        FOR I = 0 TO MySQL.TableCount-1

            TableListBox.AddItems(MySQL.Table(I))

        NEXT

    END SUB

    SUB TableListBoxClick (Sender AS QLISTBOX)

        DIM Str AS STRING, J AS INTEGER

        IF Sender.ItemIndex < 0 THEN EXIT SUB

        IF MySQL.Query("show columns from "+Sender.Item(Sender.ItemIndex)) = 0 THEN

            ShowMessage("Could not query "+Sender.Item(Sender.ItemIndex))

            EXIT SUB

        END IF

        FieldEdit.Clear

        Grid.ColCount = MySQL.FieldCount

        I = 0

        WHILE MySQL.FetchField

            Grid.Cell(I,0) = MySQL.Field.Name

            I++

        WEND

        Grid.RowCount = MySQL.RowCount+1

        IF MySQL.RowCount THEN

            J = 1

            WHILE MySQL.FetchRow

                MySQL.FieldSeek(0)

                FOR I=0 to MySQL.NumFields-1

                    Grid.Cell(I,J) = MySQL.Row(I)

                NEXT

                J++

            WEND

        END IF

    END SUB

END SUB

SUB SQLFormResize (Sender AS QFORM)

    Grid.Height = Sender.ClientHeight - Grid.Top

    Grid.Width = Sender.ClientWidth-1

    TableListBox.Width = Sender.ClientWidth-1 - TableListBox.Left

END SUB

IF MySQL.Connected THEN MySQL.Close

END


QNotifyIconData
QNotifyIconData Example

QNOTIFYICONDATA Component

QNotifyIconData is not a visible component, it's a data type with the form

   TYPE QNotifyIconData

     cbSize AS INTEGER       ' Read only

     hWnd AS INTEGER

     uID AS INTEGER

     uFlags as INTEGER

     uCallBackMessage as INTEGER

     hIcon as INTEGER

     szTip as STRING

   END TYPE

Its use is primarily restricted to the Shell_NotifyIcon API call, but you may find other uses for it as well.


QOpenDialog
QOpenDialog Example

QOpenDialog Examples

  '-- Simple demo

  DIM OpenDialog AS QOpenDialog

  IF OpenDialog.Execute THEN

    ShowMessage "You selected "+OpenDialog.FileName

  END IF

  '-- Using filters

  DIM OpenDialog AS QOpenDialog

  OpenDialog.Filter = "Picture files|*.BMP;*.ICO|All Files|*.*"

  OpenDialog.FilterIndex = 2    '' Use "All Files" as our default

  IF OpenDialog.Execute THEN

    ShowMessage "You selected "+OpenDialog.FileName

  END IF


QOutLine
QOutLine Example

QOutLine Examples

CREATE Form AS QForm

  CREATE OutLine AS QOutLine

    AddLines "Parent 1", _

             " Child of Parent 1", _

             "  Child of Child of Parent 1", _

             "Parent 2", _

             "Parent 3", _

  END CREATE

  Center

  ShowModal

END CREATE


QOvalBtn
QOvalBtn Example

QOvalbtn Examples

CREATE Form AS QForm

  CREATE OvalBtn AS QOvalBtn

    Caption = "Oval Button"

    Color = &H00FF00

  END CREATE

  ShowModal

END CREATE


QPanel
QPanel Example

QPanel Examples

  DIM Form AS QForm

  DIM Button AS QButton

  DIM Panel AS QPanel

  Panel.Parent = Form

  Panel.Width = 100

  Button.Parent = Panel

  Form.ShowModal


QPopUpMenu
PopUpMenu Example

QPopupMenu Examples

  DIM PopupMenu AS QPopupMenu

  DIM Item1 AS QMenuItem

  Item1.Caption = "Item 1"

  PopupMenu.AddItems Item1

  PopupMenu.Popup(100,100)


QRadioButton
QRadioButton Example

QRadioButton Examples

  DIM Form AS QForm

  DIM Radio1 as QRadioButton

  DIM Radio2 as QRadioButton

  DIM Radio3 as QRadioButton

  Radio1.Parent = Form

  Radio1.Top = 10

  Radio1.Caption = "Item 1"

  Radio2.Parent = Form

  Radio2.Top = 35

  Radio2.Caption = "Item 2"

  Radio3.Parent = Form

  Radio3.Top = 60

  Radio3.Caption = "Item 3"

  Form.ShowModal


QRect
QRect Example

QRECT Component

QRect is not a visible component, it's a data type with the form

   TYPE QRect

     Top AS INTEGER

     Left AS STRING

     Right AS INTEGER

     Bottom as INTEGER

   END TYPE


QRegistry

QRegistry Examples

'  Detect if your computer is connected to the internet

Const HKEY_LOCAL_MACHINE = &H80000002

DIM Registry AS QRegistry

Registry.RootKey = HKEY_LOCAL_MACHINE

Registry.OpenKey("System\CurrentControlSet\Services\RemoteAccess", 0)

IF Registry.ReadBinary("Remote Connection", 0) = 1 THEN

  ShowMessage("You're connected!")

ELSE

  ShowMessage("You're not connected!")

END IF


QRichEdit
QRichEdit Example

QRichedit Examples

  $INCLUDE "RAPIDQ.INC"

  DIM Form AS QForm

  DIM RichEdit AS QRichEdit

  RichEdit.Parent = Form

  RichEdit.Scrollbars = ssBoth

  RichEdit.AddString "Hello world!"

  Form.ShowModal


QSaveDialog
QSaveDialog Example

QSaveDialog Examples

  '-- Simple demo

  DIM SaveDialog AS QOpenDialog

  IF SaveDialog.Execute THEN

    ShowMessage "You want to save as "+SaveDialog.FileName

  END IF


QScrollBar

QScrollBar Examples

' Color Palette for Rapid-Q

DECLARE SUB ColorChange

DECLARE SUB Paint

CONST False = 0

CONST True = NOT False

'' Here's something that will convert your standard RGB to Rapid-Q's BGR.

FUNCTION ConvertRGB(R AS INTEGER, G AS INTEGER, B AS INTEGER) AS INTEGER

  ConvertRGB = (B SHL 16) OR (G SHL 8) OR R

END FUNCTION

CREATE Form AS QForm

  CREATE LabelRed AS QLabel

    Left = 10

    Top = 22

    Caption = "Red:"

  END CREATE

  CREATE LabelGreen AS QLabel

    Left = 5

    Top = 52

    Caption = "Green:"

  END CREATE

  CREATE LabelBlue AS QLabel

    Left = 10

    Top = 82

    Caption = "Blue:"

  END CREATE

  CREATE LabelNum1 AS QLabel

    Left = 270

    Top = 22

    Caption = "0"

  END CREATE

  CREATE LabelNum2 AS QLabel

    Left = 270

    Top = 52

    Caption = "0"

  END CREATE

  CREATE LabelNum3 AS QLabel

    Left = 270

    Top = 82

    Caption = "0"

  END CREATE

  CREATE ScrollRed AS QScrollBar

    Left = 50

    Top = 20

    Width = 200

    Height = 20

    Min = 0: Max = 255

    ShowHint =  True

    Hint = "Red Attribute"

    OnChange = ColorChange

  END CREATE

  CREATE ScrollGreen AS QScrollBar

    Left = 50

    Top = 50

    Width = 200

    Height = 20

    Min = 0: Max = 255

    ShowHint =  True

    Hint = "Green Attribute"

    OnChange = ColorChange

  END CREATE

  CREATE ScrollBlue AS QScrollBar

    Left = 50

    Top = 80

    Width = 200

    Height = 20

    Min = 0: Max = 255

    ShowHint =  True

    Hint = "Blue Attribute"

    OnChange = ColorChange

  END CREATE

  CREATE PaintBox AS QCanvas

    Left = 50

    Top = 110

    Height = 90

    Width = 200

    OnPaint = Paint

  END CREATE

  Caption = "Color Palette"

  Center

  ShowModal

END CREATE

SUB ColorChange

  LabelNum1.Caption = STR$(ScrollRed.Position)

  LabelNum2.Caption = STR$(ScrollGreen.Position)

  LabelNum3.Caption = STR$(ScrollBlue.Position)

  Paint

END SUB

SUB Paint

  PaintBox.Paint(0,0,ConvertRGB(ScrollRed.Position, ScrollGreen.Position, ScrollBlue.Position),&HFFFFFF)

END SUB


QScrollBox

QScrollBox Examples

CREATE Form AS QForm

  Center

  CREATE ScrollBox AS QScrollBox

    Left = 50

    CREATE Button AS QButton   '-- Create button inside scrollbox

    END CREATE

  END CREATE

  ShowModal

END CREATE


QSocket
QSocket Example

QSocket Examples

See the chatserver.bas and chatclient.bas (or chatserv.bas and chatcli.bas for Windows)

included in the Rapid-Q distribution.

Also take a look at http.bas included in the Rapid-Q for Windows distribution.


QSplitter
QSplitter Example

QSplitter Examples

$INCLUDE "RAPIDQ.INC"

CREATE Form AS QFORM

    Height = 400

    Caption = "QSplitter example"

    Center

    Visible = 1                  '-- Required

    Visible = 0                  '-- trick

    CREATE Panel AS QPANEL

        Align = alTop            '-- Fill top portion of form

        Height = 100

        Caption = "PANEL"

    END CREATE

    CREATE Splitter AS QSPLITTER '-- Note position

        Align = alTop            '-- Fill middle

        Cursor = crVSplit

        Height = 10

    END CREATE

    CREATE RichEdit AS QRICHEDIT

        Align = alClient         '-- Fill rest of form

        AddStrings "RICHEDIT"

    END CREATE

    ShowModal

END CREATE


QStatusBar

QStatusBar Examples

CREATE Form AS QForm

  Center

  CREATE StatusBar AS QStatusBar

    AddPanels "Panel 1", "Panel 2", "Panel 3"

    Panel(1).Width = 100  ' change width of Panel 2

  END CREATE

  ShowModal

END CREATE

QStringGrid Examples

CREATE Form AS QForm

  CREATE Grid AS QStringGrid

    Cell(1,1) = "hello"

  END CREATE

  Center

  ShowModal

END CREATE


QStringList

QStringList Examples

  DIM StringList1 AS QStringList

  DIM StringList2 AS QStringList

  StringList1.AddItems "Oranges","Apples"

  StringList2.AddItems "Byte","Word","Integer"

  StringList1.AddList(StringList2)

  StringList1.Sort

  ?StringList1.Text

  ?StringList1.Item(3)

  ?StringList1.IndexOf("Word")

  ?StringList1.IndexOf("hi")

  '-------------------------------------------------------

  DIM StringList AS QSTRINGLIST

  StringList.Parse("James:Brown:555-3454:House",":")

  PRINT StringList.Build(0,StringList.Count-1,",")


QTabControl
QTabControl Example

QTabControl Examples

'' Tab Control Example for Rapid-Q

'' When you hide a container (like QFORM, QTABCONTROL, and QPANEL), all the

'' components within it are also hidden.

$INCLUDE "RAPIDQ.INC"

DECLARE SUB TabChange

CREATE MainForm AS QForm

  Center

  Height = 300

  Width = 350

  Caption = "Tab Control demo"

  CREATE Tab AS QTabControl

    AddTabs "Tab 1","Tab 2","Tab 3","Tab 4"

    Width = MainForm.ClientWidth

    Height = MainForm.ClientHeight

    OnChange = TabChange

    HotTrack = True

    CREATE Panel0 AS QPanel

      Top = 40

      Left = 5

      Width = Tab.ClientWidth - 10

      Height = Tab.ClientHeight - 50

      Caption = "Panel 1"

      BevelInner = bvLowered

      CREATE Button1 AS QButton

        Caption = "Hello world!"

      END CREATE

    END CREATE

    CREATE Panel1 AS QPanel

      Top = 40

      Left = 5

      Width = Tab.ClientWidth - 10

      Height = Tab.ClientHeight - 50

      Caption = "Panel 2"

      BevelInner = bvLowered

      Visible = False

    END CREATE

    CREATE Panel2 AS QPanel

      Top = 40

      Left = 5

      Width = Tab.ClientWidth - 10

      Height = Tab.ClientHeight - 50

      Caption = "Panel 3"

      BevelInner = bvLowered

      Visible = False

    END CREATE

    CREATE Panel3 AS QPanel

      Top = 40

      Left = 5

      Width = Tab.ClientWidth - 10

      Height = Tab.ClientHeight - 50

      Caption = "Panel 4"

      BevelInner = bvLowered

      Visible = False

    END CREATE

  END CREATE

END CREATE

SUB TabChange

  SELECT CASE Tab.TabIndex

    CASE 0

      Panel0.Visible = True

      Panel1.Visible = False

      Panel2.Visible = False

      Panel3.Visible = False

    CASE 1

      Panel1.Visible = True

      Panel0.Visible = False

      Panel2.Visible = False

      Panel3.Visible = False

    CASE 2

      Panel2.Visible = True

      Panel1.Visible = False

      Panel0.Visible = False

      Panel3.Visible = False

    CASE 3

      Panel3.Visible = True

      Panel1.Visible = False

      Panel2.Visible = False

      Panel0.Visible = False

  END SELECT

END SUB

MainForm.ShowModal


QTimer

QTimer Examples

' Timer & OnKeyPress example for Rapid-Q

'       If no form is visible, Timer will not function.

'       Not for PURE CONSOLE apps, but you're allowed to MIX.

DIM Timer AS QTimer, Timer2 AS QTimer

DIM Form AS QFORM

DIM Label1 AS QLABEL, Label2 AS QLABEL

DIM Label3 AS QLABEL

SUB TimerOver

  Timer.Interval = 100

  I = I + 1

  Label1.Caption = STR$(I)

END SUB

SUB Timer2Over

  Timer2.Interval = 1000

  J = J + 1

  Label2.Caption = STR$(J)

END SUB

SUB KeyPressed (Key AS BYTE)      '' Event returns one parameter

  IF UCASE$(CHR$(Key)) = "Q" THEN

    FORM.CLOSE

  END IF

END SUB

I = 0        ' Undeclared variables are automatically global!

J = 0

FORM.CAPTION = "Timer Example"

FORM.WIDTH = 150

FORM.HEIGHT = 120

FORM.CENTER

Label1.Parent = Form

Label1.Caption = STR$(I)

Label1.Left = FORM.WIDTH/2

Label2.Parent = Form

Label2.Caption = STR$(J)

Label2.Left = FORM.WIDTH/2

Label2.Top = 40

Label3.Parent = Form

Label3.Caption = "Press 'Q' to quit'

Label3.Top = 75

Timer.Interval = 100

Timer.Enabled = 1          ' True

Timer.OnTimer = TimerOver

Timer2.Interval = 1000

Timer2.Enabled = 1          ' True

Timer2.OnTimer = Timer2Over

FORM.OnKeyPress = KeyPressed

FORM.SHOWMODAL


QTrackBar
QTrackBar Example

QTrackBar Examples

CREATE Form AS QForm

  Center

  CREATE TrackBar AS QTrackBar

    ' Initialize track bar

  END CREATE

  ShowModal

END CREATE


QCanvas
QCanvas Example

QCanvas Examples

'  Pixel by pixel credit scroller for Rapid-Q

DIM Canvas AS QCanvas

DIM Form AS QForm

DIM Timer1 AS QTimer

DIM Font AS QFont

DIM Y AS INTEGER

    Y = -20

SUB Resize

  Canvas.Height = Form.ClientHeight

  Canvas.Width = Form.ClientWidth

END SUB

SUB Paint

  Canvas.Textout (65,Y-30,"Beware the power of Rapid-Q!", &H00FF00, 0)

  Canvas.Textout (30,Y,"Credit Scroller written in Rapid-Q ", &HFFFFFF, 0)

END SUB

SUB TimerOver

  Timer1.Interval = 1  '' Can't go any lower!

  Y = Y + 1            '' Pixel by pixel!

  Paint

END SUB

Form.Width = 400

Form.Height = 200

Form.Center

Form.Color = 0

Font.Name = "Arial"

Font.Size = 12

Font.Color = &H00FF00

Canvas.Parent = Form

Canvas.Font = Font

Canvas.Color = 0

Canvas.OnPaint = Paint

Timer1.Interval = 1

Timer1.OnTimer = TimerOver

Form.Onresize = Resize

Form.ShowModal


QForm
QForm Examples

QForm Examples

  DIM Form AS QForm

  DIM Button AS QBUTTON

  Button.Parent = Form     '' Add button to form container

  Form.Center

  Form.Caption = "Hello world!"

  IF Form.ShowModal THEN

    PRINT "Return result is TRUE"

  ELSE

    PRINT "Return result is FALSE"

  END IF


QApplication
QApplication Examples

Application Examples

  Application.HintColor = &H00FF00

  CREATE Form AS QFORM

      CREATE Button AS QBUTTON

          Hint = "Button Hint"

    ShowHint = 1

      END CREATE

      ShowModal

  END CREATE