If you want to import only one value interactively in a program, you can use several components. One of them is the ValueBox component, whose properties and use are described in this chapter. You have to check the entered data for further use in your programs - such as the IP addresses, for example - to some extent yourself. But it is also unusual to be able to enter a time of 7:90, which leads internally to a time of 8:30 o' clock. You can assign a defined start value to each Valuebox. The set property ValueBox. read-only is only accepted for the types Number and Currency, but it can be read for all types. Six different types are available for the Valuebox:
(1) Type Number
Only digits are accepted in the Valuebox of type Number and the comma as decimal separator. A dot is immediately converted to a comma if the German language setting is selected.
(2) Type Date
A selected date is only transferred to the display with a double-click. The date displayed cannot be edited.
(3) Type Time
The time can be taken over from a list (time interval 30 minutes) by double-clicking on the clock symbol. Use the cursor keys to navigate through the list. You can also enter the time directly in the format hh: mm - but with leading zero - and then edit this time.
ATTENTION: You can also enter a time of 27:88 o' clock, because an interval of 00 to 99 is allowed for both the hours and minutes. The time of issue is then 7:60 but 8:00. The input 60:99 o' clock becomes 13:39 o' clock (60h: 24= 2d+12h; 99min: 60=1h+39min. Thus 13h+39min are displayed as remaining time in the 24-hour interval! Unusual - but has a system.
(4) Type Currency
Money amounts - in Germany in euros - are entered separately with euro and cent with the decimal sign! Only the comma is allowed as decimal separator. The currency symbol is only displayed in the Valuebox. Internally, only the numerical value is stored. You can only enter positive currency amounts.
(5) Type DateTime
You can select the date from the calendar and the time from the displayed list with a time difference of 30 minutes. Both values are transferred to the display by double-clicking. You can correct the values in the Valuebox. In the DateTime type Valuebox, in contrast to the Time type, you can only use the following intervals for hours 00.. 23 and minutes 00… 59. In the DateTime type Valuebox, you can only use the following intervals for hours 00… 23 and minutes 00… 59.
(6) IP address in IPv4 format
To enter, place the corsor at the first position after the last digit (default is zero) and then enter the number triple in blocks. Use the two cursor keys (> and <) to switch to the other input fields. Leading zeros are suppressed in the Valuebox. You have to check the correctness of the IP address yourself, because the entries of the numerical triple are accepted for a block in the interval of 0 to 999 (!):
Public Sub btnIPAdress_Click() Dim aMatrix As String[] Dim iCount As Integer Dim sMessage As String txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = valBoxIPAdress.Value aMatrix = Split(valBoxIPAdress.Value, ".") For iCount = 0 To aMatrix.Max sMessage = "Die IP-Adresse ist im " & (icount + 1) & ". Block fehlerhaft (" & aMatrix[iCount] & ") !" If Val(aMatrix[iCount]) < 0 Or Val(aMatrix[iCount]) > 255 Then Message.Error(sMessage) valBoxIPAdress.SetFocus Endif Next ' iCount End ' IPAdress_Click
Figure 16.9.1: Valuebox - 6 types
The source code for a project to demonstrate the use of the 6 types of a Valuebox is given here in full:
' Gambas class file Public Sub Form_Open() FMain.Center FMain.Resizable = False btnEnde.Cancel = True ' Programm-Ende mit ESC-Taste valBoxNumber.Type = valBoxNumber.Number ' valBoxNumber.ReadOnly = True valBoxDate.Type = valBoxDate.Date valBoxTime.Type = valBoxTime.Time valBoxCurrency.Type = valBoxCurrency.Currency ' valBoxCurrency.ReadOnly = True valBoxDateTime.Type = valBoxDateTime.DateTime valBoxIPAdress.Type = valBoxIPAdress.IPAddress valBoxIPAdress.Value = "192.168.100.11" End ' Form_Open Public Sub btnNumber_Click() txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = valBoxNumber.Value End ' Number_Click Public Sub btnDate_Click() txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = Format$(valBoxDate.Value, "dddd - dd.mm.yyyy") End ' Date_Click Public Sub btnTime_Click() txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = Format$(valBoxTime.Value, "hh:nn") & " Uhr" End ' Time_Click Public Sub btnCurrency_Click() txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = valBoxCurrency.Value & " Euro" End ' Currency_Click Public Sub btnDateTime_Click() txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = Format$(valBoxDateTime.Value, "dd.mm.yyyy - hh:nn") & " Uhr" End ' DateTime_Click Public Sub btnIPAdress_Click() Dim aMatrix As String[] Dim iCount As Integer Dim sMessage As String txbDisplay.Clear txbDisplay.Alignment = Align.BottomRight txbDisplay.Text = valBoxIPAdress.Value aMatrix = Split(valBoxIPAdress.Value, ".") For iCount = 0 To aMatrix.Max If Val(aMatrix[iCount]) < 0 Or Val(aMatrix[iCount]) > 255 Then sMessage = "IP-Adresse im " & (icount + 1) & ". Block fehlerhaft (" & aMatrix[iCount] & ") !" Message.Error(sMessage) valBoxIPAdress.SetFocus Endif Next ' iCount End ' IPAdress_Click Public Sub btnEnde_Click() FMain.Close End ' Close
In the download area you will find the source repository.
Articles and Projects