Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUT] VB.NET How To Make A Simple Global Message [TUT] [Explained]

There are 2 ways you can display a custom global message when your application loads.

I shall post the snippet's then explain what it does below

PHP Code

<?php 
Imports System
.Net 

PHP Code

<?php 
Try
    
Dim TempPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
    
Dim FileToDeleteelete As String
    FileToDeleteelete 
= TempPath & "/globmsg.txt"
    
If System.IO.File.Exists(FileToDeleteelete) = True Then
    System
.IO.File.Delete(FileToDeleteelete)
    
End If
    
My.Computer.Network.DownloadFile("http://Google.com/global/message1.txt", TempPath & "/globmsg.txt")
    
Dim Reader As New IO.StreamReader(TempPath & "/globmsg.txt")
    
Dim FileContents As String = Reader.ReadToEnd
    Reader
.Close()
    If 
FileContents = "" Then
    
Else
    
MsgBox(FileContents, MsgBoxStyle.Information, "Gloabl Message")
    
End If
    If 
System.IO.File.Exists(FileToDeleteelete) = True Then
    System
.IO.File.Delete(FileToDeleteelete)
    
End If

  Catch
    
MsgBox("Gobal Message Couldnt be found", MsgBoxStyle.Critical, "London Worm")
  
End Try
    
End Sub 

PHP Code

<?php 
Imports System
.Net 

This tells VB that it is going to contact the internet

PHP Code

<?php 
Dim TempPath 
As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) 

Puts Temp path as a string, inside APPdata

PHP Code

<?php 
Dim FileToDeleteelete 
As String
    FileToDeleteelete 
= TempPath & "/globmsg.txt"
    
If System.IO.File.Exists(FileToDeleteelete) = True Then
    System
.IO.File.Delete(FileToDeleteelete)
    
End If 

Checks if the file already exists, if it does it will delete it

PHP Code

<?php 
My
.Computer.Network.DownloadFile("http://Google.com/global/message1.txt", TempPath & "/globmsg.txt") 

Downloads the file, your txt file, to temppath (Application Data) as "globmsg.txt"

PHP Code

<?php 
Dim Reader 
As New IO.StreamReader(TempPath & "/globmsg.txt")
    
Dim FileContents As String = Reader.ReadToEnd
    Reader
.Close() 

The part that reads the txt file, in this case "globmsg.txt"

PHP Code

<?php 
If FileContents = "" Then
    
Else
    
MsgBox(FileContents, MsgBoxStyle.Information, "Gloabl Message")
    
End If 

If the file is empty it skips this part, if it contains text it will display it as a message box

PHP Code

<?php 
If System.IO.File.Exists(FileToDeleteelete) = True Then
    System
.IO.File.Delete(FileToDeleteelete)
    
End If 

And then deletes the file for next time

PHP Code

<?php 
MsgBox
("Gobal Message Couldnt be found", MsgBoxStyle.Critical, "London Worm") 

The catch happens if it cannot download or read the txt file, if that is the case this will display






Here is the second method

PHP Code

<?php 
Imports System
.Net 

PHP Code

<?php 
Dim Strin 
As String
  Dim WebC 
As New WebClient
  Strin 
= WebC.DownloadString("http://Google.com/global/message2.txt")
  If 
Strin.Contains("message") Then
    Dim Split
() As String = Strin.Split("|")
    
MsgBox(Split(1), MsgBoxStyle.Information, "Global Message")
  
End If 

PHP Code

<?php 
Imports System
.Net 

This tells VB that it is going to contact the internet

PHP Code

<?php 
Dim Strin 
As String
  Dim WebC 
As New WebClient 

Sets strin as anything
and sets WebC as a WebClient

PHP Code

<?php 
WebC
.DownloadString("http://Google.com/global/message2.txt") 

Downloads your TXT file as a string

PHP Code

<?php 
If Strin.Contains("message") Then
    Dim Split
() As String = Strin.Split("|")
    
MsgBox(Split(1), MsgBoxStyle.Information, "Global Message")
  
End If 

If the TXT file contains "message" then it will carry on
If the TXT file contains "message|Global message", it will split it after the "|"
A message box will then appear with the message displaying what is after the "|"

An example txt file to this would be

Code
message|Welcome to London Worm V2.1
Please read the detailed about me for more information

Hope You enjoyed this tutorial and i also hope it benefited you all

Thank you

Megan
Why even save it to the computer?

You can do something as simple as:
Code
Try
    Dim program As New WebClient
    Dim ProgramGobalMessage As String = program.DownloadString("http://google.com/message.txt")
Catch ex As WebException
    MessageBox.Show("Error, The database is currently down please try again later", "Program", MessageBoxButtons.OK, MessageBoxIcon.Error)
  Catch ex As Exception
    MessageBox.Show("Error, Something went wrong with the database please try again later", "Program", MessageBoxButtons.OK, MessageBoxIcon.Error)
  End Try

If Not ProgramGobalMessage = "" Then
    MessageBox.Show(ProgramGobalMessage, "Global Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End If
[Image: tqE7M8d.png]
(Jun 18, 2011 09:57 AM)ShadowHelper Wrote:  Why even save it to the computer?

Its just a method of doing it
Its easier to understand
Nice, never knew what Google Global was.

Is this like a news downloader?

Thanks!
The links i put in arent real :P

It could be used for it,
I t just there to be shows as a global message on a form loading

Giving news to someone about a product or something
Why not just use Webclient.DownloadString to download string-data from the server?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by SIM-3364521Jan 13, 2019 08:09 AM 11 689 Jan 13, 2019 08:09 AM
Last Post: SIM-3364521
[Shell] by _thenotsofriendlyghostFeb 1, 2017 09:04 AM 4 194 Feb 1, 2017 09:04 AM
Last Post: _thenotsofriendlyghost
[.NET] by AρεϰJan 27, 2015 08:09 PM 9 270 Jan 27, 2015 08:09 PM
Last Post: Poppy