Linux Basic
September 05, 2010, 11:01:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Linux Basic forums have just been installed. This, I hope, will be the place to talk about the new breed of Basics coming out for the Linux operating system. A place to get informed as well as help each other out with programming and installation issues. Be warned, I am as green as you are. I am here to learn as well.
 
   Home   Help Login Register  
Pages: [1] 2 3 ... 10
 1 
 on: August 19, 2010, 08:30:50 PM 
Started by luke - Last post by luke
hi all i have made a 1 bot login with a message packet for yahoo on there 102 protocol
just add a socket to your form gb.net   put your id and pass in the script
if you wont to receive a pm from this script change the whoto  to  the id ya want to send to
maybe change the message ya wont to send
and click play in Gambas
if you ha filled out the everything right then it should login for you and send a message



PUBLIC id AS String pass AS String
PUBLIC ycookie AS String tcookie AS String
PUBLIC whoto AS String msg AS String
PUBLIC pck AS String

PUBLIC SUB Form_Open()

id = "put you id here" 'id to login with
pass = "put your password here" ' password for id
whoto = "user to send the message to in here" ' the user id ya wanna send the private message to
msg = "Hellow There" ' the message text ya wanna send to the whoto id
Socket1.Connect("login.yahoo.com", 80)
END


PUBLIC SUB Socket1_Ready()
DIM x AS Integer
IF Len(ycookie) < 1 THEN
pck = "GET http://login.yahoo.com/config/login?.src=bl&login=" & id & "&passwd=" & pass & " HTTP/1.0" & Chr(13) & Chr(10)
pck = pck & "Connection: Keep-Alive" & Chr(13) & Chr(10)
pck = pck & "Accept: */*" & Chr(13) & Chr(10)
pck = pck & "Accept-Language: en" & Chr(13) & Chr(10) & Chr(13) & Chr(10)

IF socket1.Status = Net.Connected THEN WRITE #Socket1, PCK, Len(PCK)
END IF
IF Len(ycookie) > 1 THEN
pck = ""
pck = "YMSG" & Chr(0) & Chr(&66) & Chr(0) & Chr(&01) & String(3, Chr(0)) & Chr(&4c) & String(8, Chr(0))
IF socket1.Status = Net.Connected THEN WRITE #Socket1, PCK, Len(PCK)
WAIT 1
pck = ""
x = 59 + Len(id) + Len(id) + Len(id) + Len(ycookie) + Len(tcookie)
pck = pck & "YMSG" & Chr(&00) & Chr(&66) & Chr(0) & String(2, Chr(&01)) & Chr(Int(x MOD 256)) & Chr(&02) & Chr(&26) & Chr(&5a) & Chr(&55) & Chr(&aa)
pck = pck & Chr(&55) & String(4, Chr(0)) & Chr(&30) & Chr(&C0) & Chr(&80) & id & Chr(&C0) & Chr(&80) & "2" & Chr(&C0) & Chr(&80) & id
pck = pck & Chr(&C0) & Chr(&80) & "1" & Chr(&C0) & Chr(&80) & id & Chr(&C0) & Chr(&80) & "244" & Chr(&C0) & Chr(&80) & "16277215"
pck = pck & Chr(&C0) & Chr(&80) & "2" & Chr(&C0) & Chr(&80) & Chr(&C0) & Chr(&80) & "6" & Chr(&C0) & Chr(&80) & ycookie & ";" & Chr(&20) & tcookie & Chr(&26) & "lang=en;" & Chr(&C0) & Chr(&80)
pck = pck & "98" & Chr(&C0) & Chr(&80) & "us" & Chr(&C0) & Chr(&80)
IF socket1.Status = Net.Connected THEN WRITE #Socket1, PCK, Len(PCK)
END IF
END

PUBLIC SUB Socket1_Read()
DIM S AS String
DIM x AS Integer
 
      READ #Socket1, S, Lof(Socket1)
IF Len(ycookie) < 1 THEN
ycookie = Mid(s, InStr(s, "Y="), InStr(s, "1;") - InStr(s, "Y=") + 2)
tcookie = Mid(s, InStr(s, "T="), InStr(s, "--;") - InStr(s, "T=") + 3)
  
  socket1.Close
  Socket1.Connect("98.136.48.79", 8002)
  END IF
  
  PRINT s
 IF Len(s) > 780 THEN
 'IF the packet = more than 780 we send the pm

pck = ""
x = 87 + Len(whoto) + Len(id) + Len(msg)
pck = pck & "YMSG" & Chr(&00) & Chr(&66) & Chr(0) & Chr(&01) & Chr(0) & Chr(Int(x MOD 256)) & Chr(0) & Chr(&06) & Chr(&5a) & Chr(&55) & Chr(&aa) & Chr(&56)
pck = pck & Chr(0) & Chr(&4a) & Chr(&de) & Chr(&5C) & Chr(&31) & Chr(&C0) & Chr(&80) & id
pck = pck & Chr(&C0) & Chr(&80) & "5" & Chr(&C0) & Chr(&80) & whoto & Chr(&C0) & Chr(&80) & "14" & Chr(&C0) & Chr(&80) & Chr(&1b)
pck = pck & "[#000000m<font face=" & Chr(&22) & "Arial" & Chr(&22) & " size=" & Chr(&22) & "12" & Chr(&22) & ">" & msg
pck = pck & Chr(&20) & Chr(&C0) & Chr(&80) & "97" & Chr(&C0) & Chr(&80) & "0" & Chr(&C0) & Chr(&80) & "63" & Chr(&C0) & Chr(&80)
pck = pck & ";0" & Chr(&C0) & Chr(&80) & "64" & Chr(&C0) & Chr(&80) & "0" & Chr(&C0) & Chr(&80) & "1002" & Chr(&C0) & Chr(&80) & "1" & Chr(&C0) & Chr(&80)
IF socket1.Status = Net.Connected THEN WRITE #Socket1, PCK, Len(PCK)
END IF
END


have fun all hope it works for you all Grin

 2 
 on: February 17, 2010, 01:40:45 PM 
Started by SteveDee - Last post by enricopallawitschini
Just declare Property as String[]!?

Like:

Property Something as String[]

Private $Something as String[]
PUBLIC FUNCTION Something_Read() AS String[]
 
  RETURN $Something
 
END

PUBLIC SUB Something_Write(Value as String[])
 
  $Something=Value = strNew
 
END


And from Outside just use it like an array(which it is).

MyClass.Something.Add(Value,Index)
MyString=MyClass.Something[index]

 3 
 on: February 12, 2010, 03:06:28 AM 
Started by enricopallawitschini - Last post by enricopallawitschini
I need help to get this to work!

I'm trying to write a frontend for fst (a possibility to load vst-plugins for jack).

There are severel problems I ran into.

1. If I use the (somewhere else found) form of starting a bash-process

$bash=Exec ["bash","--noediting"] for read write as "BASH"

I dont get any read events
So I tryed

$bash=Exec ["bash"] for Input Output as "BASH"

which seems to work.

2. In the BASH_read event I check if the "$ " is shown, if so I write a command to BASH like

Print #$bash, "fst /home/erich/Musik/VST/FST_Gui/BLOCKFISH_3.dll" & gb.newline;

It sometimes works, but sometimes I get Errors like:

can't load plugin /home/erich/Musik/VST/FST_Gui/BLOCKFISH_3.d

or

fst is cut to st so bash doesnt recognise the command. (just now I cant reproduce this Error, so I cant post it properly)

3. As I start multiple plugins and want to embed them I also want to be able to end them.
If I write:
Print #$bash,"^C" & gb.newline;
nothing happens

If I do a Try $bash.Close afterwards all Plugins close when im closing the last process, but until then all are alive.

Please help

 4 
 on: January 15, 2010, 03:04:47 PM 
Started by drcrazy4 - Last post by drcrazy4
Nevermind I just realised it's a problem with the FOR statement. If anybody else ever has the same problem, this code works:
Code:
PUBLIC SUB subTotal()

  DIM i AS Integer
  DIM sT AS Float
  DIM amount AS Float
 
  sT = 0
  amount = 0

  FOR i = 0 TO salesJournal.Count - 1
    amount = Val(salesJournal[i][3])
    sT = sT + amount
  NEXT

  customerDisplay("Subtotal", sT, "", "")
 
END

 5 
 on: January 15, 2010, 02:56:42 PM 
Started by drcrazy4 - Last post by drcrazy4
Sorry you'll have to forgive me if I'm missing something obvious as I'm still learning the ropes. I'm basically trying to add up all of the values in a column (in a columnview). Here is my code:
Code:
PUBLIC SUB subTotal()

  DIM i AS Integer
  DIM sT AS Float
  DIM amount AS Float
  
  sT = 0
  amount = 0

  IF salesJournal.Count > 1
    FOR i = 1 TO salesJournal.Count
      amount = Val(salesJournal[i][3])
      sT = sT + amount
    NEXT
  ENDIF
  
  sT = sT + Val(salesJournal[0][3])
  customerDisplay("Subtotal", sT, "", "")
  
END
The problem is that I get the error 'Null key' on the line
Code:
amount = Val(salesJournal[i][3])
when there is more than 1 item in the columnview. If anybody could help with this I'd greatly appreciate it, as it's driving me mad. Thanks!

PS. I have already checked to make sure that salesJournal[1][3] etc. does have a value.

 6 
 on: December 29, 2009, 05:48:23 AM 
Started by SteveDee - Last post by SteveDee
Earlier this year I used the excellent "WiFi Radar" program to determine the channels used by other near-by access points, and found they were mostly clustered near the top end of the band. I then selected a low channel for my router to minimise the chances of interference.

However, I recently checked once again and found other APs on the channel I was using!

With an ever increasing number of WiFi APs, what I needed was an indication of both channel AND signal level to determine the safest channel to use, hence this mini project.

I'm using 2 Linux commands and I pipe the output for use by my app:-
- iwconfig is required to find the local Wifi interface (i.e. on the pc you are using).
- iwlist is used to scan for any Wifi Access Points within range.

The iwlist command requires root privileges. One solution is to modify your sudoers file by adding the following line at the end of the file;
Code:
%admin ALL = NOPASSWD: /sbin/iwlist

This will allow any user with admin rights to run this WiFiScanner.

ToDo list; I've kept the program listed below fairly minimal, so it does not include any error handling. There are other parameters that may be of interest (such as MAC address) that can easily be extracted from the iwlist output (in a terminal run "sudo iwlist" to see what is available).

Other possible enhancements include:-
- listing APs in order of signal (i.e. highest to lowest Link Quality)
- keeping a list of all APs detected in the last (say) month
- adding a simple graph for each AP (see my Simple Chart Class from an earlier post)
- creating a graph where the x-axis is channels 1 to 13 and y-axis is largest signal for each channel

Maybe if you have an idea you can also post it here.

The basic WifiScanner code;

Code:
' Gambas class file
'**************************************************************************
'WifiScanner
'Like the excellent app "Wifi Radar", this app lists Wifi Access Points
'but also shows Link Quality in addition to Channel number.
'This should help to select a Wifi Channel that is less prone to
'interference from strong neighbouring signals.
'As iwlist requires root Privileges to run, you may need to mod sudoers.
'Steve Davis
'Dec 2009
'***************************************************************************

PUBLIC strAccPoints AS String[10] 'to hold Access Point + Channel + Quality

PUBLIC SUB Form_Open()
  lblWifiInterface.Text = GetWifiInterface()
  tmrScanner.Start()
END
'---------------------------------------------------
PUBLIC FUNCTION GetWifiInterface() AS String
DIM hFile AS File
DIM strLine AS String
DIM strWifi AS String

  SHELL "iwconfig > /tmp/Pipe_iwconfig" WAIT
  hFile = PIPE "/tmp/Pipe_iwconfig" FOR INPUT
  DO UNTIL Eof(hFile)
    LINE INPUT #hFile, strLine
    IF InStr(strLine, "ESSID") > 0 THEN 'found a Wifi interface
      strWifi = Trim(Mid(strLine, 1, InStr(strLine, " ")))
    ENDIF
  LOOP
  RETURN strWifi
END
'---------------------------------------------------
PUBLIC FUNCTION GetESSIDs(strInterface AS String) AS Boolean
DIM hFile AS File
DIM strLine AS String
DIM strAccessPoint AS String
DIM strChannel AS String
DIM strQuality AS String
DIM index AS Integer

  SHELL "sudo iwlist " & strInterface & " scan > /tmp/Pipe_iwlist" WAIT
  hFile = PIPE "/tmp/Pipe_iwlist" FOR INPUT
  DO UNTIL Eof(hFile)
    LINE INPUT #hFile, strLine
    'find access point...
    IF InStr(strLine, "ESSID") > 0 THEN 'found a Wifi access point
      strAccessPoint = Mid(strLine, InStr(strLine, ":") + 1)
      strAccPoints[index] = Mid(strAccessPoint, 2, Len(strAccessPoint) - 2)
    ENDIF
    '...get channel number...
    IF InStr(strLine, "Channel") > 0 THEN 'found access point Channel
      strChannel = Mid(strLine, InStr(strLine, "Channel"))
       strChannel = Mid(strChannel, 1, InStr(strChannel, ")") - 1)
      strAccPoints[index] = strAccPoints[index] & " : " & strChannel
    ENDIF
    '...get Link Quality
    IF InStr(strLine, "Quality") > 0 THEN 'found access point Link Quality
      strQuality = Mid(strLine, InStr(strLine, ":") + 1)
       strQuality = Mid(strQuality, 1, InStr(strQuality, " ") - 1)
      strAccPoints[index] = strAccPoints[index] & " : " & strQuality & "%"
      INC index
    ENDIF
  LOOP 
END
'---------------------------------------------------
PUBLIC SUB tmrScanner_Timer()
DIM index AS Integer   

  GetESSIDs(lblWifiInterface.Text)
  lstAccessPoints.Clear()
  FOR index = 0 TO 9
    lstAccessPoints.Add(strAccPoints[index], index)
  NEXT
END

 7 
 on: December 26, 2009, 06:41:14 AM 
Started by SteveDee - Last post by SteveDee
What I've discovered is that Gambas does not appear to like other support files in the project directory. In the 2 projects that were giving me grief, I had included either graphics or sound files within the project folder.

For example, within Home/Gambas/myProject I had a sound file called bell.wav as this was used in my project. Within the IDE Project tree, this was shown under an imaginary directory called "Data", so it looks like Gambas understands why these files are there. However, when I try to Make an exe, this seems to confuse the compiler (presumably it scans this file using all available cpu time, then falls over!).

If I remove the bell.wav file, Gambas will happily create an exe, and I can also create an installation package. I get the same behaviour with graphics files (e.g. JPG, PNG).

In any case, it doesn't look like my support files (in this virtual Data directory) are included in the installation pacakage, which is part of the reason I put them there. It would be nice if there was a file similar to the setup.lst file in VB6, which could be manually edited to add/remove support files, and change other install options.

I must also mention that Gambas appears to be primarily for KDE. I run Gnome and have found there to be many Gnome specific problems, so this may turn out to be another. However, if you want to try to reproduce this problem, just create and save a new project. Then make sure you can create an exe (obviously your program won't do much). Now add either a sound file(.wav) or graphic (.png or .jpg) to the project folder, and try to create an exe once again. Please let me know if you succeed or fail!

One final point is that I also included a sub-directory in my projects called "exe" which is where I create the exe file. But moving this to a location outside the project directory did not affect this problem.

 8 
 on: December 23, 2009, 11:12:15 AM 
Started by SteveDee - Last post by SteveDee
I've just started experiencing problems when trying to create an exe or package using Gambas 2.13 under Ubuntu 9.10.

For example, I may use Project > Compile and the status bar says "Compiling Project Whatever.." and within a few seconds its done, no problem. But when I try to make an exe, it displays the "Compiling..." message, then after 7 or 8 secs the Gambas windows goes grey, and if I don't force it to quit it will produce a huge file (several GB in size).

So, does anyone know:-
1. if this is a known problem?
2. is there some useful way to debug compilation, like a log file somewhere that will tell me what is going on, or how far it got before failing?

 9 
 on: December 18, 2009, 10:37:34 AM 
Started by SteveDee - Last post by SteveDee
There are times where it might be useful to have a simple way to monitor basic data from your application.

Two examples that I have faced in industry are:-
1. Running a "headless" data server application. With no user interface, it is useful to have an independant means of checking that your app is running, how long it has been "up" and to provide a list of recent errors.
2. A data management system where you wish to provide a simple data summary to production line staff, anywhere in the plant, without giving them access to the full and relatively complex main application.

A solution I favor is to pump summary data out to an HTML file, with read only access from anywhere on the network.

You can't assume that everybody is computer savvy, but the chances are that anyone who has used a computer will be familiar with a web browser, even if they have never used a wordprocessor or spreadsheet app. So by providing them with a link, operators at almost any level should be able to view your data.

Since we want the browser to show current data, we simply code a refresh command (to the browser) in the html file with a suitable update period.

If you want to explore this, start a new Gambas project and add a timer to the main form. Then add this code to the main form:-

Code:
PUBLIC lngCount AS Long
PUBLIC dteStartTime AS Date

PUBLIC SUB Form_Open()

  dteStartTime = Now
  WITH Timer1
    .Delay = 5000
    .Start
  END WITH
 
END

PUBLIC SUB Timer1_Timer()
DIM strTemp AS String
DIM strRunTime AS String
 
  'Simulate a "process" temperature
  INC lngCount
  strRunTime = CStr(DateDiff(dteStartTime, Now, gb.Minute))
  strTemp = CStr(Round((Rnd(25)), -2))
  HTML.SaveReport("Current Temperature", strTemp, strRunTime, lngCount)

END

Now add a new module to your project and name it "HTML". Paste the code below into your HTML module.

Code:
' Gambas module file

PRIVATE sngLastReading AS Single

PUBLIC FUNCTION SaveReport(strHeading AS String, strTempC AS String, strRun AS String, lngReadings AS Long) AS Boolean

DIM strReportFile AS String
DIM strReport AS String
DIM strTempDiff AS String
DIM hFile AS File

  strReportFile = User.Home & "/Report.html"
  strTempDiff = CStr(Round(CSng(strTempC) - sngLastReading, -2))
   
    'Build Report
    strReport = "<html><head>" & Chr(10)
    strReport = strReport & "<title>"
    strReport = strReport & strHeading
    strReport = strReport & "</title>" & Chr(10)
    'auto refresh every 5 secs
    strReport = strReport & "<meta http-equiv=" "refresh" " content=5>"
    strReport = strReport & "</head>"
    'back colour
    strReport = strReport & "<body bgcolor=" "#E0E0FF" ">"
    strReport = strReport & "<body>"
    'bold text
    strReport = strReport & "<p>" & "<B>" & "Real-Time HTML Report - " & strHeading & "</B>" & "</p>"
    'Normal
    strReport = strReport & "<p>" & "A simple example of an HTML monitor screen" & "</p>"
    'horiz line & blank line
    strReport = strReport & "<HR>" & "<BR>"
    'table
    strReport = strReport & "<table border=" "1" ">"
    strReport = strReport & "<tr>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Time: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">" & Format(Time, "hh:nn:ss") & "</font></td>"
    strReport = strReport & "</tr>"
    strReport = strReport & "<tr>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Date: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">" & Format(Date, "dd-mmmm-yyyy") & "</font></td>"
    strReport = strReport & "</tr>"
    strReport = strReport & "<tr>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Temperature: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" " color=" "blue" ">" & strTempC & " C" & "</font></td>"
    strReport = strReport & "</tr>"
    strReport = strReport & "<tr>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Temp change: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">" & strTempDiff & " C" & "</font></td>"
    strReport = strReport & "</tr>"
    strReport = strReport & "<tr>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Number of Readings: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">" & lngReadings & "</font></td>"
    strReport = strReport & "</tr>"
    strReport = strReport & "<tr>"   
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Browser Refresh Rate: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">5 seconds</font></td>"   
    strReport = strReport & "</tr>"
    strReport = strReport & "<tr>"   
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">Server up time: </font></td>"
    strReport = strReport & "<td><font size=" "2" " face=" "Verdana" ">" & strRun & " mins</font></td>"   
    strReport = strReport & "</tr>"   
    strReport = strReport & "</table><p><br></p>"
    strReport = strReport & "<HR>"
    'embed a graphic
    strReport = strReport & "<EMBED SRC=" & Application.Path & "/logo.jpg" " HEIGHT=" "75" " WIDTH=" "250" ">"
    strReport = strReport & "<BR>" & "<HR>" & "<BR>"
    'play a sound
    strReport = strReport & "<EMBED SRC=" & Application.Path & "/bell.wav" " HEIGHT=" "0" " WIDTH=" "0" ">"
    'add a Marquee
    strReport = strReport & "<MARQUEE>Here we go again!</MARQUEE>"
   
    strReport = strReport & "</body>"
    strReport = strReport & "</html>"
    sngLastReading = CSng(strTempC)
   
  TRY KILL strReportFile
  hFile = OPEN strReportFile FOR APPEND 
  WRITE #hFile, strReport, Len(strReport)
  CLOSE #hFile 
 
END


Run the project and point your web browser at the Report.html file in your Home directory.

I couldn't see an option to attached my sound & graphic files to this post, so if you wish you can provide your own and add these to the Gambas project folder. However, this wont stop the code above from running.

 10 
 on: December 07, 2009, 06:40:44 AM 
Started by SteveDee - Last post by SteveDee
I know I'm still locked into my old VB.Classic mind set, but how should you code for array properties in a class?

In VB I would do something like this:-

Code:
Dim mstrContactName(100)as string

Public Property Get strContactName(ByVal lngIndex As Long) As String

    strContactName = mstrContactName(lngIndex)

End Property

Private Property Let strContactName(ByVal lngIndex As Long, ByVal strNew As String)

    mstrContactName(lngIndex) = strNew

End Property

But in Gambas you can't pass variables to a Property. So I have to result to using a method like this:-

Code:
PUBLIC FUNCTION GetContactName(lngIndex AS Long) AS String
 
  RETURN strContact[lngIndex]
 
END

PUBLIC FUNCTION LetContactName(lngIndex AS Long, strNew as String) AS String
 
  strContact[lngIndex] = strNew
 
END

So my question: Is there a better way?

Pages: [1] 2 3 ... 10
Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!