|
Hi
I am kinda new to vb.net and I am having problems with code that works when it suits it. The code is meant to check if data has been entered into the text boxes. For some unknown reason it works on one form but the same code copied and pasted does not work on a different form.
this the code.
'This checks the textboxes to see if the data entered is correct
Dim ctrlx As Control
For Each ctrlx In Controls
If TypeOf ctrlx Is TextBox Then
If ctrlx.Text = "" Then
ctrlx.Focus()
MessageBox.Show("Please enter the required data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
End If
Next
I hope u will be able to help me,
twsted f8
|
|
|
|
|
Don't post the same message twice.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
You cannot compare the type of control with TextBox Class. The control has to be compared with the type of TextBox.
Possibly the the code snippet will resolve your issue
For Each ctrl As Control In Me.Controls
If ctrl.GetType() Is GetType(TextBox) Then
If ctrl.Text="" Then
MessageBox.Show("Message",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
ctrl.Focus()
End IF
End If
Next
Santosh Metal
|
|
|
|
|
hello i am new in vb.net
and i am doing phone direcroty application, so in this application input is users name, middle name, surname,home phone,mobile,email,houseno, add,town,postcode,counrty etc and i have used all this as string variable
and code is like this
Option Explicit On <br />
Option Strict On<br />
Public Class frmPhone<br />
Inherits System.Windows.Forms.Form<br />
<br />
'Globle variables<br />
Dim FileNumber, Position As Integer, FileName As String<br />
Dim MyFile As String = "phonelist.txt"<br />
<br />
'create record type the name of record is PhoneList<br />
Structure PhoneList<br />
Dim Inits As String<br />
Dim Gender As String<br />
<VBFixedString(20)> Dim FName As String<br />
<VBFixedString(20)> Dim SName As String<br />
<VBFixedArray(2)> Dim MName As String<br />
<VBFixedArray(20)> Dim HomePhone As String<br />
<VBFixedArray(20)> Dim Mobile As String<br />
<VBFixedArray(30)> Dim Email As String<br />
<VBFixedArray(5)> Dim HouseNo As String<br />
<VBFixedArray(20)> Dim FLine As String<br />
<VBFixedArray(20)> Dim SLine As String<br />
<VBFixedArray(20)> Dim Town As String<br />
<VBFixedArray(10)> Dim PostCode As String<br />
<VBFixedArray(15)> Dim Country As String<br />
End Structure<br />
'Function to use last record<br />
Private Function FindLastRecordNo() As Integer<br />
Dim Temp As PhoneList, FileNum As Integer<br />
FileNum = FreeFile() 'Free file number<br />
FileOpen(FileNum, MyFile, OpenMode.Random, , , Len(Temp))<br />
FindLastRecordNo = 1<br />
Do While Not EOF(FileNum) 'EOF() function is using to detect the end of file<br />
Dim vt As ValueType = Temp<br />
FileGet(FileNum, vt, ) 'Get file file function is using to get record from random file<br />
Temp = CType(vt, PhoneList)<br />
FindLastRecordNo = FindLastRecordNo + 1<br />
Loop<br />
FileClose(FileNum)<br />
End Function<br />
<br />
<br />
Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click<br />
Dim Response As DialogResult<br />
Dim PhoneBook As PhoneList, LastRecord, I As Integer<br />
txtName.Text = StrConv(txtName.Text, VbStrConv.ProperCase)<br />
txtMiddle.Text = StrConv(txtMiddle.Text, VbStrConv.ProperCase)<br />
txtSurname.Text = StrConv(txtSurname.Text, VbStrConv.ProperCase)<br />
txtFirstLine.Text = StrConv(txtFirstLine.Text, VbStrConv.ProperCase)<br />
txtSecondLine.Text = StrConv(txtSecondLine.Text, VbStrConv.ProperCase)<br />
txtTown.Text = StrConv(txtTown.Text, VbStrConv.ProperCase)<br />
txtPostCode.Text = StrConv(txtPostCode.Text, VbStrConv.UpperCase)<br />
LastRecord = FindLastRecordNo() 'call last record function <br />
'Check if all three text boxes in tabpage add is not blank<br />
FileNumber = FreeFile()<br />
FileOpen(FileNumber, MyFile, OpenMode.Random, , , Len(PhoneBook))<br />
PhoneBook.Inits = cboInits.Text<br />
PhoneBook.Gender = cboGender.Text<br />
PhoneBook.FName = txtName.Text<br />
PhoneBook.MName = txtMiddle.Text<br />
PhoneBook.SName = txtSurname.Text<br />
PhoneBook.HomePhone = CStr(Val(txtHome.Text))<br />
PhoneBook.Mobile = CStr(Val(txtMobile.Text))<br />
PhoneBook.Email = CStr(Val(txtEmail.Text))<br />
PhoneBook.HouseNo = CStr(Val(txtHouse.Text))<br />
PhoneBook.FLine = txtFirstLine.Text<br />
PhoneBook.SLine = txtSecondLine.Text<br />
PhoneBook.Town = txtTown.Text<br />
PhoneBook.PostCode = txtPostCode.Text<br />
PhoneBook.Country = cboCountry.Text<br />
FilePut(FileNumber, PhoneBook, LastRecord)<br />
FileClose(FileNumber)<br />
MessageBox.Show("Item successfuly Saved", "Item Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
End Class
but it's shows error that bad record length i have debug program several times but i can not understand what to do, in local windows it's shows few information like name, middle name,surname,home phone,mobile but rest is nothing but how can i solve this problem
can any body help me with this
waiting for your kind rep.
-- modified at 14:49 Sunday 16th September, 2007
|
|
|
|
|
Please only post the part of the code that is having trouble. You posted more than necessary.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
hello sir
thanks for your rep.
i have modifid the code
so can you please tell me how to solve this problem
waiting for your kind rep.
thanks
|
|
|
|
|
What on earth are FileOpen, FilePut, etc ? Nasty VB6 legacy methods, or methods you wrote ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: FileOpen, FilePut, etc ? Nasty VB6 legacy methods
I vaguely remember seeing something hideous like that in the early VB days.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
first of all thanks all who sent their posts
and to be very honest i wanted to use VBFixedString and that time string was in my mind and i typed array and all problem starts
so this is very stupid mistake
but any way job done and problem sorted
thanks all again
|
|
|
|
|
sir
I need simple codings in .net .I am at beogners stage.
|
|
|
|
|
Sounds like you should be buying a book, working through it, then moving on to the articles on this site. No-one can post anything that is likely to help you at this point, in a forum reply.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Mahendhirans wrote: I need simple codings in .net
You've come to a site that has plenty of code samples, articles, etc. Post only if you have a specific question. Also, work on your English skills will get better when you engage in dialogue with people on this site.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
|
Need simple code in vb6 to convert a .txt file or string to a .wav file using a selected voice. I am new at this & can't seem to find any snippets anywhere.
Robert, still trying
|
|
|
|
|
Well, as you're new, why are you using VB6, a dead, unsupported and terrible language ? VB.NET is free.
What you're asking for is not simple, hence the lack of code snippets.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: Well, as you're new, why are you using VB6, a dead, unsupported and terrible language ? VB.NET is free.
What you're asking for is not simple, hence the lack of code snippets.
Christian;
It's my understanding vb.NET will not run on Windows 98. Maybe it's time I upgrade??
Robert, still trying
|
|
|
|
|
don't know if that's true or not, but it's free, so it's worth trying.
Yes, it's definately time for a new OS.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You are probably right. Before I rush to the computer store, do you know if the vb6 code I have will work in VB.NET and will the compiled .exe from VB.NET work on a Windows 98 machine?
Robert, still trying
|
|
|
|
|
Robert from Florida wrote: do you know if the vb6 code I have will work in VB.NET
Absolutely not. VB6 was a disaster, Microsoft basically created a whole new language with VB like syntax. There is no clear upgrade path.
Robert from Florida wrote: will the compiled .exe from VB.NET work on a Windows 98 machine?
I don't know, the 2005 .NET runtime ( which is 2.0 ) may not go back that far.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Well, I guess it's worth a shot & a good reason to get a new computer. Thanks for your time & info.
Robert, still trying
|
|
|
|
|
Glad to help
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Just feel I should add my 2c here.
Christian isn't just encouraging you to upgrade for the hell of it. VB6 is old and no longer supported by Microsoft. If you are learning to program then it will teach you some very very bad practices. Also theres a hell of a lot more support around for the .Net environment.
|
|
|
|
|
I second that...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I,m after some vb 2003 source code for the card game Blackjack.
Can anyone help?
Regards
Zeldacat
|
|
|
|
|
Have you tried a simple search[^]?
---
single minded; short sighted; long gone;
|
|
|
|