Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes you'd like to leave information for your users - just a short text note
'they can call up from within your application - an online version of "Tip of the Day"
'or simply periodic information about revisions or issues.
'This method requires that you put a text file on your server. In this example,
'the filename is "gbsnippets.msg", which exists on the gbSnippets server.
'Primary Code:
'The URLDownloadToFile gets the file, but you should use DeleteURLCacheEntry
'first to ensure that you pull from the server, not from the local cache.
Local URLPath As Asciiz*%Max_Path, LocalPath As Asciiz*%Max_Path, temp$
URLPath = "http://www.garybeene.com/files/gbsnippets.msg"
LocalPath = Exe.Path$ + "gbsnippets.msg"
DeleteURLCacheEntry(URLPath) '1 = success clear the cache
URLDownloadToFile (ByVal 0, URLPath, LocalPath, 0, 0) 'API to download the file, store on local PC
'the URLDownloadToFile API does not provide a progress indicator of how many bytes have
'been downloaded, so it is best used for very small files. Limiting the file to just
'a few lines of text is especially appropriate.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "WinINET.inc"
Global hDlg as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Message of the Day",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Get Message", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
GetDailyMessage
End If
End Function
Sub GetDailyMessage
Local URLPath As Asciiz*%Max_Path, LocalPath As Asciiz*%Max_Path, temp$
URLPath = "http://www.garybeene.com/files/gbsnippets.msg"
LocalPath = Exe.Path$ + "gbsnippets.msg"
DeleteURLCacheEntry(URLPath) '1 = success clear the cache
If URLDownloadToFile (ByVal 0, URLPath, LocalPath, 0, 0) = 0 Then
Open Exe.Path$ + "gbsnippets.msg" For Binary As #1
Get$ #1, Lof(1), temp$
Close #1
MsgBox temp$, %MB_Ok Or %MB_IconInformation, "gbSnippets Daily Message"
Else
MsgBox "gbSnippets message not found!", %MB_Ok Or %MB_IconExclamation, "gbSnippets Daily Message"
End If
End Sub
'gbs_00043
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm