Useful Links Code

Post

Posted
Rating:
#1 (In Topic #243)
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
I'm writing a Gambas Project Review Utility and I wanted to include some useful links as references for various Gambasy things such as database, html and graphics references.
 
I created a form with a single scroll view with the background set to Color.White.
It dynamically adds URLLabels with the Tooltip set to display the actual hyperlink and a short description.
This data is contained in a small txt file (Links.Txt) in a format of:
Displayed Name | HyperLink | Short Description.

Clicking on any URLLabel opens the default browser with the address coming from URLLabel.Link.
The order of display is the order in which the lines of the file is read.
<IMG src="https://drive.google.com/drive/folders/1LUuCFHyzb_a4j04Pc-a8Z0k8cnGQWhMb?usp=sharing"> </IMG>

Form Code as below.

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Private NewLink As URLLabel
  4. Private TmpAry As String[]
  5.  
  6. Public Sub Form_Open()
  7.   Dim Buffer As Integer = 3
  8.   Dim FileName As String = Application.Path &/ "Links.Txt" '\{Change this for the actual location of the file}
  9.   Dim LinkFile As File
  10.   Dim TmpLine As String = ""
  11.   Dim TmpInt as Integer = 0  ' <----<< This code was missing from the Original Post. (Edit)
  12.   Dim Ylocation As Integer = Buffer
  13.   Dim SetOdd As Boolean = True
  14.  
  15.   Scv_Links.Width = Me.Width - 10
  16.   Scv_Links.Height = Me.Height - 10
  17.  
  18.   If Exist(FileName) Then
  19.     Scv_Links.Children.Clear
  20.     LinkFile = Open FileName For Input
  21.     While Not Eof(LinkFile)
  22.       Line Input #LinkFile, TmpLine
  23.       If ((Left(TmpLine, 1) <> "#") Or (Trim(TmpLine) <> "")) Then
  24.         TmpAry = Split(TmpLine, "|")
  25.         If TmpAry.Count = 3 Then
  26.           NewLink = New URLLabel(Scv_Links) As "Link#" & Str(TmpInt)
  27.           NewLink.Text = TmpAry[0]
  28.           NewLink.Link = TmpAry[1]
  29.           NewLink.Tooltip = TmpAry[1] & Gb.CrLf & TmpAry[2]
  30.           NewLink.Height = 24
  31.           NewLink.Width = Scv_Links.Width - 25
  32.           NewLink.Left = 5
  33.           NewLink.Top = YLocation
  34.           YLocation += Buffer + NewLink.Height
  35.           If SetOdd Then
  36.             NewLink.Background = Color.RGB(195, 223, 223)
  37.             SetOdd = False
  38.           Else
  39.             NewLink.Background = Color.RGB(255, 255, 223)
  40.             SetOdd = True
  41.           Endif
  42.           NewLink.Foreground = Color.LinkForeground
  43.         Endif
  44.       Endif
  45.     Wend
  46.  
  47. Public Sub Form_KeyPress()
  48.   If Key.Code = Key.Esc Then Me.Close
  49.  

Attachment

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
I get an error: -

Unknown identifier: Tmpint in FMain.class:25
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
I had some other code that was linked to my Program so must have removed it when I took that out.

For those who have already copied the code

Code (gambas)

  1. Dim TmpInt as Integer = 0
just needs to be amended to variable declaration at the top of the sub

I'll do an edit and put it back in

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi Quin,

Matt and I have looked at your code and made a few changes. Does this help?

Attachment
Online now: Yes Back to the top

Post

Posted
Rating:
#5
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
I Like it !.

When did the array.Max turn up or has it always been there ?
Apparently it appears in other controls as well ie: ScrollView1.Children.Max
I assume another little gem from Benoît and that's going to be very useful indeed. !

If {test} Then  Continue ?
Now that's a new one on me - Let me think about that one as I need to get my head around how that works
in an IF - Then - Else clause ?

Much cleaner code over all - Nice to lean some new things I must say.

The bit that has me a bit perplexed is :

Code (gambas)

  1. NewLink = New URLLabel(ScrollView1) As "Link"
The 'As ("Link")' code is setting the Name element of the control and it 'should' be unique which is why I added the Str(Number) to it at each creation. Obviously different for created controls.
I'm wondering what would happen if you wanted to do more complex functions with it ?
I'll play with that one and see if there are any exceptions or perhaps the compiler creates a unique token code for each new control ?

Cheers,
A lot of food for thought.
Quin.

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Guru
cogier is in the usergroup ‘Guru’
When did the array.Max turn up or has it always been there ?
It's been around for some time, it is just the same as .Count -1

Continue jumps to Next, try this: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3. For iCount As Integer = 1 To 10
  4.   If Odd(iCount) Then Continue
  5.   Print iCount
  6.  
  7. 'Result = 2, 4, 6, 8, 10
  8.  
The 'As ("Link")' code is setting the Name element ….
The program does not actually need the As "Link" to run but I have added a routine that will show you how you could use it. There is no need add separate links for each URLLabel as you can use Last to find out which item was Clicked, Entered or whatever.

Attachment
Online now: Yes Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
Cedron is in the usergroup ‘Regular’
 I learned "File.Load", "array.Max", and "Odd()" from this.  Thanks.

.... and carry a big stick!
Online now: No Back to the top
1 guest and 0 members have just viewed this.