Segments of Code that come from the pastNot all the following code has been developed by me, it is only a list of old free tips used under the old Visual Basics version and that can work well under NSbasic CE also. I am resuming, trying and adjusting if any this old code and i will post it here as soon as i will be sure that the code runs fine. (Code has been tested by NSbasic CE but you use it at your own risk) 1) Split a string and use its content as you like. This code was useful to load (for example) a Combo or List Box without using many .Additem calls and particularly to load and modify ,on running time, all the items you need simply changing the string. This is the code: Dim ITEM, n ITEM = "First |Second |Third |Fourth |The Last" Do While Len( ITEM ) n = InStr( ITEM + "|", "|") List1.AddItem Left( ITEM, n - 1) ITEM = Mid( ITEM, n + 1) Loop This little routine is much more useful than you may think. Use it with an object array and you will be able to write more efficient and compact code. 2) Dir, an helpful instruction to check the content of your device Dir is an instruction of MS FileSystem.Dll so to use it in NSbasic CE you have to add to your program this object. ADDOBJECT "FileSystem" I think that the use of Dir is well known but i quote it here anyway as i found it useful in many cases. You can use it to find id a file or a folder exists in this simple way: Dim sPath, SPath = " [Path to search]" If Right(sPath,1)="\" then sPath=sPath & " [File name to search] " else sPath = sPath & "\" & " [File name to search] " end if If Len(FileSystem.Dir(sPath))<>0 then Print "File found" Or adding few code's lines you may find all files or all subdirs for a selected path and put them in a List,box Dim sDir, iput, filece iput = " [string containing the full directory path to check] " sDir = FileSystem.Dir(iput) Do While Len(sDir) If sDir <> "" Then List1.Additem sDir sDir = FileSystem.Dir( ) Loop The Jolly characters are supported (example : iput=" \windows\*.* ") Be aware that Dir instruction is good but slow so if you have to work with a great number of items it may be better use other instructions. 3) To save space on the small Pocket PC/WinCE devices. To create a graphic interface for a CE unit is not easy because you have to insert, sometime, into a small space many objects. Even if you solve the matter it may happen that the informations to shows remain too large. Think about, for example, to a full file path. This few lines of code can help you to show the relevant information trimming the full path to fit it into the limited textbox/label on the screen. Function LongPath(Lpath, Lmax) Dim I, LblLen, StrLen, TmpStr TmpStr=Lpath LblLen=Lmax If Len(TmpStr)<=LblLen then LongPath = TmpStr Exit Function End If LblLen = LblLen-6 For i = Len(TmpStr) - LblLen to Len(TmpStr) if Mid(TmpStr,i,1) = "\" then exit For Next LongPath = Left(TmpStr,4) & "..." & Right(TmpStr,Len(TmpStr)-(i-1)) End Function Adding a Button and two TextBox to a form you may try how the function works.(I think that some adjustment may be necessary even if it runs well) Using Code 2) and 3) it should be possible to get a File ListBox that show Files' path (even if trimmed) without use an Horizontal scroll bar that solve the matter but, usually, using some space. 4) Some code for a tip To continue to check for using better the CE unit small screen you can find here some further code that can help you. It happens sometime that it should be correct to use a caption to better explain how to use a command or clarify the meaning of an icon on the command that may be not clearly read on the little screen. In the last version of VB it is very easy to create some "TIP" to be shown when you move the mouse on the command, but .......in NSbasic CE ? So i scrolled the dust from an old code created for the old VB3 and i adjusted it to obtain about the same behvior. Create a new form on your CE unit and put on it the following : Output.scalemode=3 ADDOBJECT "Label","Label1", 91, 21, 98, 21 Label1.BackColor = 16777215 Label1.ForeColor = 0 Label1.BorderStyle = 1 Label1.Visible=False ADDOBJECT "CommandButton","Button1", 70, 77, 104, 32 Button1.Tag = "This is a TIP trail" Running it you see so a command button missing of caption. Add now the following code to your program form: Sub output_mousemove(button, shift, x, y) If (x >= 65 And x =< 175) And (y >= 75 And y =< 110) Then Label1.Top = Button1.Top + Button1.Height Label1.Left = Button1.Left + Button1.Width/2 Label1.visible = True Label1.Caption = Button1.Tag Else Label1.visible=False End If End Sub What you get now is that if you move your stylus near the button a little label is shown with the string stored into the Tag property of the Button1 (according to the NSB HandleBook the code for the Stylus to use with button variable is = 0 ) The sensible border may be created using few pixels so you can anyway put the Button1 near other other objects. With a Select Case/End select routine and some fantasy you may also create instructions to use the code for multiple object if they support the TAG property. Remember also to put as first code's line in the Sub Button1_Click, if any, the following line: Label1.visible=False So using the command you can close the Tip window otherwise i you move the stylus on any other place in the form the label will be cancelled. ATTENTION- Some units' screens appear to not reply quickly to the MouseMove event. 5) Deselect a selected item in a list or combobox Sometime a selected item in a ListBox or ComboBox remain highlighted even if you want to see the full list unselected. You may unselect a previously selected item inserting the following line of code: ListBox1.Listindex = -1 6) Some code for textbox handling The textboxes are one of the most used controls that allow to perform input and output of strings in a program. There are some lines of code to apply to use this control better. A) to get the default text highlighted when the text box gotfocus to allow the user to insert immediatly the new string use this: Sub textbox1_gotfocus() Textbox1.selstart=0 Textbox1.sellength=Len(textbox1.Text) End Sub B) To use when you want user to add his input text after the default text Sub textbox1_gotfocus() textbox1.selstart = Len(textbox1.Text) End Sub C) To create an Input TextBox that accepts numbers as input only Sub TextBox1_Change If Instr("1234567890",Right(Textbox1.Text,1))=0 Then TextBox1.Text = Left(TextBox1.Text,Len(TextBox1.Text)-1) TextBox1.selstart=Len(TextBox1.Text) End If End Sub 7) Code to show any pictures in Landscape or Portrait mode.(by efsoft) To use this NSB code you must use the S309 picture box ocx (free) that is able to handle Bmp,Gif and Jpg files, instead of the MS picture box. ppath= '(full path and file's name here)
'°°°° establish the picture type
If Len(FileSystem.Dir(ppath & ".jpg")) Then photo = ppath & ".jpg"
If Len(FileSystem.Dir(ppath & ".gif")) Then photo = ppath & ".gif"
If Len(FileSystem.Dir(ppath & ".bmp")) Then photo = ppath & ".bmp"
Pic0.Picture=photo
'°°°°° check if picture type is Portrait or Landscape
If Pic0.imageWidth - Pic0.imageHeight >0 then
Pic0.move 5,65,230,150
Pic0.Visible= true
else
pic0.move 83,25,150,195
pic0.visible=true
End if
End If
End Sub You may get ppath from your code or type it using a TextBox 8) Two common listboxes and few Code's lines and here are the VB DirListBox and the FileListBox under NSBasic.(by efsoft) Add to a Form 2 ListBoxes and name them DirListBox and FileListBox enabling vertical ScrollBars. Add the code below And FileSystem object.. Option Explicit
Dim DFlag, Dir1
Dim PStore(10)
Sub DirListBox_Click()
Dim Dk, Dx, TT
If DirListBox.ListCount - 1 = 0 Then
Dir1 = DirListBox.List(0)
PStore(0) = Dir1
DFlag = 0
Call DirList(Dir1)
Else
If DirListBox.ListIndex > DFlag Then TT = 1
If DirListBox.ListIndex = DFlag Then TT = 2
If DirListBox.ListIndex < DFlag Then TT = 3
Select Case TT
Case 1
DFlag = DFlag + 1
Dk = DirListBox.ListIndex: Dir1 = DirListBox.List(Dk)
PStore(DFlag) = Dir1
DirListBox.Clear
For Dx = 0 To DFlag: DirListBox.AddItem PStore(Dx): Next
Call DirList(Dir1)
Case 2
Exit Sub
Case 3
Dk = DirListBox.ListIndex: DFlag = Dk
Dir1 = DirListBox.List(Dk)
PStore(DFlag + 1) = ""
DirListBox.Clear
For Dx = 0 To DFlag: DirListBox.AddItem PStore(Dx): Next
Call DirList(Dir1)
End Select
End If
End Sub
Sub DirList(Dir1)
Dim sDir, sDirListBox
sDir = FileSystem1.Dir(Dir1 & "*.*", 16)
Do While Len(sDir)
If InStr(sDir, ".") = 0 Then
DirListBox.AddItem Dir1 & sDir & "\"
End If
sDir = FileSystem1.Dir()
Loop
FileListBox.Clear
sDirListBox = FileSystem1.Dir(Dir1 & "*.*")
Do While Len(sDirListBox)
FileListBox.AddItem LCase(sDirListBox)
sDirListBox = FileSystem1.Dir()
Loop
End Sub