|
Thanks
|
|
|
|
|
I would say don't do it.
Why not just use the VB6 Timer control[^]. It does exactly the same job and it is already there for you to use without any messing about.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
There's multiple levels of stupidity in this, but the part where you still use VB6 definitely takes the cake.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: There's multiple levels of stupidity in this, but the part where you still use VB6 definitely takes the cake.
Wow, that's definitely signature material
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi friends,
If you like 3D Graphics programming, I have some interesting code which deals with adding light to a 3D scene.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=72519&lngWId=1
Hope it is informative.
Regards.
|
|
|
|
|
Very interesting, but this is not a Visual Basic question. Please use a more appropriate forum for this type of post.
|
|
|
|
|
I was going to reply that you should write an article until I noticed it is VB6 compatible, so don't bother, writing an article gor a language that has not been supported for a number of years is sort of stupid.
|
|
|
|
|
Is there any way to detect if the computer is going to restart using visual basic?
Thanks
|
|
|
|
|
in the form's closing event one of the close reasons is windowsshutdown. not sure how accurate it is but...
If e.CloseReason=CloseReason.WindowsShutDown Then
...
End If
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Yea that works however, i believe if you logoff, it still triggers that event. For my application, i need to detect a logoff vs a restart.
|
|
|
|
|
Hey, I'm a very beginner so please don't laugh
I want to validate a date user inputs:
Dim scr_time As Date
dim ok as boolean
System.Console.WriteLine("Enter screening date & time [DD/MM/YYYY HH/MM]")
scr_time = System.Console.ReadLine()
ValidateDate(scr_time, ok)
Sub ValidateDate(ByVal scr_time As String, ByRef bol_isvalid As Boolean)
If IsDate(scr_time) Then
bol_isvalid = True
Else
bol_isvalid = False
End If
End Sub
When entered 'notdate' the error says "Conversion from string "notdate" to type 'Date' is not valid."
Is that because I declared scr_time as date, instead of string? If I declare the date as string is
now >= scr_date
going to work fine?
Second question regarding validation of number:
Dim cnt_adult As Integer
System.Console.WriteLine("How many adult tickets required?")
cnt_adult = System.Console.ReadLine()
ValidateNumber(cnt_adult, ok)
If ok Then
System.Console.WriteLine()
Else
System.Console.WriteLine("Incorrect value. Press any key to try again.")
System.Console.ReadKey()
GoTo sale
End If
Sub ValidateNumber(ByVal text As String, ByRef bol_isvalid As Boolean)
If IsNumeric(text) Then
bol_isvalid = True
Else
bol_isvalid = False
End If
End Sub
"Conversion from string "t" to type 'Integer' is not valid."
I know the solution would be to declare the variable cnt_adult as string, by I need it as integer so I can multiply it with another integer later.
modified on Wednesday, October 7, 2009 3:41 PM
|
|
|
|
|
Use the TryCatch structured error handling, it will help you wonders, or you can also use Int32.TryParse[^] to convert a string to a numeric.
|
|
|
|
|
I don't want to convert entered by user letters to equivalent numbers, I just want program to make sure the user inputs only numbers where asked, if he enters anything else I will ask him to enter it untill its numbers only [loop].
|
|
|
|
|
If you read the documentation for ReadLine you will see that the very first line states:
Reads the next line of characters from the standard input stream.
**NOTE** it says characters. Not numbers. Not hieroglyphics. Characters.
Therefore you will have to use int.TryParse and DateTime.TryParse (the last of these will fail incidentally given your code. Use HH:MM not HH/MM) to get the data into the form that you want.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Actually characters include numbers.
|
|
|
|
|
Well since you obviously already know everything, why did you ask for help?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I don't know everything, furthermore I know much less than you regarding this topic, however I'm certain that the numbers are characters and ReadLine reads them.
dim int_number as integer
System.Console.WriteLine("Enter number")
int_number = System.Console.ReadLine()
System.Console.WriteLine(int_number)
Examples of characters include letters, numerical digits, and common punctuation marks (such as '.' or '-'). from wikipedia.org
btw. I respect your knowledge [as seen on your profile] but what you said was mistake, wasn't it?
Or maybe I'm wrong, or didn't understand you quiet well, then explain me please.
Thank you for your time.
added:
oh, I understand now what's the misunderstanding. "characters" can refer to a letters only or a group of signs incl. letters, numbers, punctuation marks. So the meaning of a character in this quote "Reads the next line of characters from the standard input stream." is general [character may be a letter or a number ect]
modified on Wednesday, October 7, 2009 2:12 PM
|
|
|
|
|
Yup your 'added:' is correct.
Readline() reads a series of characters and returns them as a String . Your code works because, behind the scenes, the VB compiler 'sees' that you want an int and does the casting for you. Just to confirm this for your own satisfaction, run the code and enter '22f', after a bit you should get an exception message saying 'The cast from string to int was unsuccessful.', or similar. Now you haven't done any casting, so it must have been done for you. (FYI: your code won't even compile in C#. Another reason not to do it this way, just in case you have to change language for some reason. )
In C# your code is almost identical:
int int_number = 0;
System.Console.WriteLine("Enter number");
int_number = System.Console.ReadLine();
System.Console.WriteLine(int_number);
Anyway, if you always treat the value from a ReadLine() as a string, you won't get any run-time errors, regardless of what the user enters. You can then attempt the conversion yourself, in a way that you can control. Using the TryParse() methods of the various Types is about the most easily controlled way of doing it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
Declare cnt_adult as string , and then do
ok = Integer.TryParse(cnt_adult)
|
|
|
|
|
Use a temporary string to read the input.
Dim userInput as String
Dim isValid as Boolean
Dim cnt_adult as Integer
userInput = System.Console.ReadLine()
isValid = Integer.TryParse(userInput, cnt_adult)
|
|
|
|
|
I see that others have already replied but here's my effort anyway:
Dim cnt_adult As Integer
Dim userInput As String
Dim ok As Boolean
ok = False
While (ok = False)
System.Console.WriteLine("How many adult tickets required?")
userInput = System.Console.ReadLine()
ok = Integer.TryParse(userInput, cnt_adult)
End While
Sorry for not replying earlier, but I was in the middle of a very, very important game.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
When I try to make a connection to the db from VB I get this error message.
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
I'm am using the default named instance.
The connection works just fine with the SQL Server Management Studio and the configuration manager. I've done two days of searching and trying various items that I've found but nothing seems to work.
Any help would be most appreciated.
|
|
|
|
|
Any chance we can see your connection string?
|
|
|
|
|
Thanks Elliot,
This is the connection string from the machine.config file in the C:\WINDOWS\Microsoft.net\framework\v2.0.50727\CONFIG file.
<add name="LocalSqlServer" connectionstring="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|GGTEST.mdf;User Instance=true" providername="System.Data.SqlClient">;
Garth
|
|
|
|