Hi people..... this is my first program in VB.
Before this i have done programming in C,C++.
I read some of the chapters from Black book of VB; but still having problem in the initial part itself.
The program is I have to take a number in any of the forms; Octal, binary or hexadecimal convert it in the form required by user and display the result.
Am done with the logic of program; but having problems.. - Private Sub Form_Load()
-
-
Dim intext As String
-
intext = Text1.Text
-
-
Dim outtext As String
-
outtext = Text2.Text
-
if (option1.Value=true) and (option4.Value=true)
-
outtext = intext
-
End If
-
-
-
-
-
-
-
End Sub
First of all am not understanding why it creates so many procedures; every time i click something.......
And its showing error in if statement dont know why..
Is it because of option? i deleted some sub procedures above it; before that also it was showing an error.
Am using Microsoft Visual Basic.
Please tell me fast.
36 2506
Sorry folks, i troubled u i got the mistake; i had forgotten to write THEN.
But u can still tell me what's the use of different procedures; which we get when we click any of the controls?
I mean are they private? or public? Are they excluded from other code?
What if we dont make them?
Sorry folks, i troubled u i got the mistake; i had forgotten to write THEN.
But u can still tell me what's the use of different procedures; which we get when we click any of the controls?
I mean are they private? or public? Are they excluded from other code?
What if we dont make them?
In visual basic,when you just double-click a control,it automatically enters the code window creating the procedure for the basic event of the control you clicked..for example,if you double click command button,it creates a procedure Command1_Click,because click is the most usual event one will perform on a command button.if you want some other event you can choose in the code window.
This feature makes the task of developers easier.If you dont want to write anything inside the created procedure,just leave it or if you still feel annoying delete it.(Try not to double click any of the unnecessary controls in design time).
Since you are a beginner,you may feel this annoying,but once you get involved with visual basic,you'd really love this feature-it saves your time!
Remember visual basic does an event driven programming.
It's the same program; where i got to convert a number from one number system to another..... m a bit confused regarding scope of different variables.
Here is my program that i wrote in Microsoft Visual Basic 6.0; for now its having only 3 options and that too converting a number from one to same number system.. Not actually converting also.. but its not displaying anything in text2.
Here is the code.I dont know how will i copy the form of VB.
Public Sub Text1_Change()
Static inno As Integer
inno = Text1.Text
End Sub
Public Sub Text2_Change()
Static outno As Integer
outno = Text2.Text
End Sub
Public Sub Command1_Click()
If Option1.Value = True And Option4.Value = True Then
outno = inno
End If
If Option2.Value = True And Option5.Value = True Then
outno = inno
End If
If Option3.Value = True And Option6.Value = True Then
outno = inno
End If
'If Option1.Value = True And Option6.Value = True Then
'outno = inno
'End If
'Dim counter As Integer
'For counter = 0 To 9
End Sub
In visual basic,when you just double-click a control,it automatically enters the code window creating the procedure for the basic event of the control you clicked..for example,if you double click command button,it creates a procedure Command1_Click,because click is the most usual event one will perform on a command button.if you want some other event you can choose in the code window.
This feature makes the task of developers easier.If you dont want to write anything inside the created procedure,just leave it or if you still feel annoying delete it.(Try not to double click any of the unnecessary controls in design time).
Since you are a beginner,you may feel this annoying,but once you get involved with visual basic,you'd really love this feature-it saves your time!
Remember visual basic does an event driven programming.
Thanks.
But m not sure whether i understand the meaning of event driven programming.
Here is the code.I dont know how will i copy the form of VB.
Public Sub Text1_Change()
Static inno As Integer
inno = Text1.Text
End Sub
Public Sub Text2_Change()
Static outno As Integer
outno = Text2.Text
End Sub
Public Sub Command1_Click()
If Option1.Value = True And Option4.Value = True Then
outno = inno
End If
End Sub
I have chopped your code a little for size but looking at it you do not seem to be calling the Text2_Change sub inorder to change the text so all the program does when you click on the command1 is set the value of outno
also you are declaring the integers whenever you call the text change subs which does not look correct
i think if i understand what you are trying to do you will need to have something like -
Public Sub Command1_Click()
If Option1.Value = True And Option4.Value = True Then
outno = inno
End If
Text2_Change()
End Sub
Please reply fast. I'm stuck with first program itself.
Thanks.
But m not sure whether i understand the meaning of event driven programming.
vb reacts to every possible event occuring to any control in the form.if it is a command button it may be subjected to many possible events like click,double click,mouse move etc. And the users can make their own coding under any event they wish to monitor.
This kind of programming is event driven programming.
vb reacts to every possible event occuring to any control in the form.if it is a command button it may be subjected to many possible events like click,double click,mouse move etc. And the users can make their own coding under any event they wish to monitor.
This kind of programming is event driven programming.
thank you so much...
Can u plz tell me wats wrong with my code?
Please reply fast. I'm stuck with first program itself.
to display something in textbox2 u must have text2.text=some value(i mean text2.text must be on the left side-assignment is from right to left)..
Why use static variables and declare it inside text box change event?instead you can declare variables generally(outside all events-so that the variables become public to the entire form)
I have chopped your code a little for size but looking at it you do not seem to be calling the Text2_Change sub inorder to change the text so all the program does when you click on the command1 is set the value of outno
also you are declaring the integers whenever you call the text change subs which does not look correct
i think if i understand what you are trying to do you will need to have something like -
Public Sub Command1_Click()
If Option1.Value = True And Option4.Value = True Then
outno = inno
End If
Text2_Change()
End Sub
Thanks budy.
May be because m new in VB, i didnt understand why do i hav to keep it blank the text2 event?
And wats wrong with integer?
I mean earlier i had used string and instead of text i had used text1.text but i was getting a error that i cannot assign it to an array... M not sure wether i got that.
to display something in textbox2 u must have text2.text=some value(i mean text2.text must be on the left side-assignment is from right to left)..
Why use static variables and declare it inside text box change event?instead you can declare variables generally(outside all events-so that the variables become public to the entire form)
But then that will be global if m not wrong... and its not a good programming practise to declare variables as global.... so m willing to avoid that habit from beginning itself......... otherwise later it causes problems.
to display something in textbox2 u must have text2.text=some value(i mean text2.text must be on the left side-assignment is from right to left)..
Why use static variables and declare it inside text box change event?instead you can declare variables generally(outside all events-so that the variables become public to the entire form)
I did text2.text=outno.. but still invain.
I also used debugger but all that m gettin in here is this:
For all the text boxes, options, variables no value is getting displayed other than the message: expression not defined in context for inno and for rest ; out of context..
Why is it so?
I also used debugger but all that m gettin in here is this:
For all the text boxes, options, variables no value is getting displayed other than the message: expression not defined in context for inno and for rest ; out of context..
Why is it so?
Are you sure that you made the right calculations for converting numbers(you didnt show that in your code) and stored it in outno?
Better have a command button so that the user may click it after entering the number in the text box and selecting the conversion type option button. Finally include text2.text=outno in command button's click event.
Okay..just give me some time and i'll design the proj and attach it.
Are you sure that you made the right calculations for converting numbers(you didnt show that in your code) and stored it in outno?
Better have a command button so that the user may click it after entering the number in the text box and selecting the conversion type option button. Finally include text2.text=outno in command button's click event.
Okay..just give me some time and i'll design the proj and attach it.
I have done the same things as u said........ given command button for conversion; option buttons for selecting a no. system and has also provided text box for entering data.
I dont know how to display that here.
There doesnt come any option to copy the entire form...
If u tell me how to do that i can display the form design over here.
can anybody plz tell me how do i attach my visual basic form over here?
So that u can understand the form design and whatever is goin wrong.
Thanks budy.
May be because m new in VB, i didnt understand why do i hav to keep it blank the text2 event?
And wats wrong with integer?
I mean earlier i had used string and instead of text i had used text1.text but i was getting a error that i cannot assign it to an array... M not sure wether i got that.
Sorry, when I had used text2_change() that was as a call to the subroutine as I had slightly miss read the code but it was not very clear, please can you advise
1. how the form is set up
2. what you want to happen when the command button is clicked , including how the display changes
I am really unclear what you are trying to achieve with this form but I have posted an example of some cut down code below that might help , again apologies if this is completely different to what you are trying to do!!
also please note that I have not included any error checking for this so if you have this code and enter a string instead of a number into the box it will throw an exception also I don't have VB as I use vb.net so the subroutines may look a little different -
-
Public Class Form1
-
-
' declare two integers used to hold the in number and out number
-
-
Dim inno As Integer
-
Dim outno As Integer
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
-
' when the button is clicked and the IF statement matches change outno to a value of inno x2
-
-
inno = Text1.Text
-
-
If "A" = "A" And "B" = "B" Then
-
outno = inno * 2
-
-
' change text2.text to show outno
-
-
Text2.Text = outno
-
End If
-
-
End Sub
-
-
End Class
sorry, my programming habits are probably not the best , I have just noticed the comment you made about the variables
I am not really fully sure how it works but possibly it may do what you want if you use - -
-
Private inno As Integer
-
Private outno As Integer
-
-
Thanks a lot..
In my program two text boxes are there; one to insert the number and other to display the result. One command button; which when clicked will perform actual conversion. And two frames to chose the number to be converted is in which number system as well the number to be obtained should be in which no. system with in all 6 option buttons..
My code is now working for same system changes; where earlier it was not.
What i mean by same system changes is........Base of input as well as output is the same may be octal/binary/hexadecimal.
But now m getting some error while converting a no. from hexadecimal to binary.....
The code is as follows: - Public outno As String
-
Public inno As String
-
Public Sub Text1_Change()
-
inno = Text1.Text
-
End Sub
-
-
Public Sub Command1_Click()
-
-
If Option1.Value = True And Option4.Value = True Then
-
outno = inno
-
End If
-
-
If Option2.Value = True And Option5.Value = True Then
-
outno = inno
-
End If
-
-
If Option3.Value = True And Option6.Value = True Then
-
outno = inno
-
End If
-
-
If Option1.Value = True And Option6.Value = True Then
-
outno = hextobinary()
-
End If
-
-
Text2.Text = outno
-
End Sub
-
-
Public Sub Text2_Change()
-
Text2.Text = outno
-
End Sub
-
Function hextobinary()
-
Dim i As Integer
-
Dim store As Long
-
Dim reminder As String
-
Dim quot As Integer
-
Dim temp As String
-
For i = 0 To 9
-
If (inno(i) >= 0 And inno(i) <= 9) Then
-
store = store + inno(i) * pow(16, i)
-
-
ElseIf (inno(i) = a) Then
-
inno(i) = 10
-
store = store + inno(i) * pow(16, i)
-
ElseIf (inno(i) = b) Then
-
inno(i) = 11
-
store = store + inno(i) * pow(16, i)
-
ElseIf (inno(i) = c) Then
-
inno(i) = 12
-
store = store + inno(i) * pow(16, i)
-
ElseIf (inno(i) = d) Then
-
inno(i) = 13
-
store = store + inno(i) * pow(16, i)
-
ElseIf (inno(i) = d) Then
-
inno(i) = 14
-
store = store + inno(i) * pow(16, i)
-
ElseIf (inno(i) = f) Then
-
inno(i) = 15
-
store = store + inno(i) * pow(16, i)
-
End If
-
Next i
-
-
If store! = 0 Then
-
i = 0
-
Do
-
reminder(i) = store Mod 2
-
quot = store / 2
-
i = i + 1
-
While quot! = 0
-
For j = 9 To 0
-
outno(i) = reminder(j)
-
i = i + 1
-
j = j - 1
-
Exit For
-
Return
-
End Function
its showing some error as an array is expected.....
I changed the data type of inno with array but there is no such data-type....
I understood, the error is because i have taken input in a number and accessing it as array in for loop.
But then can somebody tell me how do i get my number in an array?.... there is no such data-type.. or is there?
In case of the function oct..it converts an expression to octal system number...can we have another number in some number system which can get converted in octal...
you seem to be accessing inno as an array ie: array(no of item)
if you are trying to select as specific character within the string / integer you will be better using the MID command I think
lol please bear in mind that there may be better ways of doing this and I have not tried to work out the conversion but here is some code to split the string -
-
For n = 1 To inno.Length
-
-
value = (Mid(inno, n, 1))
-
-
' whatever it is that you wish to do with this value
-
-
Next
-
-
to split it to an array - -
-
dim value(inno.length) as string
-
-
For n = 1 To inno.Length
-
-
value(n) = (Mid(inno, n, 1))
-
-
Next
-
-
i have designed a simple application which helps in base conversion..
but the problem is i dont know how to attach it here..
anyone knows how??
i have designed a simple application which helps in base conversion..
but the problem is i dont know how to attach it here..
anyone knows how??
Even i have designed it. And even i dont know how ill post that here.......
Moreover i never asked for design..... M just gettin stuck somewhere in my code..
Even i have designed it. And even i dont know how ill post that here.......
Moreover i never asked for design..... M just gettin stuck somewhere in my code..
As this is your first program in vb(and you have some difficulties with the coding),i thought you might need an example.. Do you need it? If yes i'll have to figure out a way..
you seem to be accessing inno as an array ie: array(no of item)
if you are trying to select as specific character within the string / integer you will be better using the MID command I think
lol please bear in mind that there may be better ways of doing this and I have not tried to work out the conversion but here is some code to split the string -
-
For n = 1 To inno.Length
-
-
value = (Mid(inno, n, 1))
-
-
' whatever it is that you wish to do with this value
-
-
Next
-
-
to split it to an array - -
-
dim value(inno.length) as string
-
-
For n = 1 To inno.Length
-
-
value(n) = (Mid(inno, n, 1))
-
-
Next
-
-
Am unable to do inno.length..
The compiler is showing error.
Is it the wrong way or sth else..
Is pow function not there in VB? what do we do for exponential?
I got how to do exponential thing........its just by using[b] '^['/B].
But now can someone tell me how we use not equal to sign in VB?
I got how to do exponential thing........its just by using[b] '^['/B].
But now can someone tell me how we use not equal to sign in VB?
I got that to by writting the expression in'( )' and using <> sign; but now m not getting equal to sign.
I got that to by writting the expression in'( )' and using <> sign; but now m not getting equal to sign.
use NOT keyword..for example, 'if not a=b and not a=c then ...'
Am unable to do inno.length..
The compiler is showing error.
Is it the wrong way or sth else..
what error message are you getting though ????
what error message are you getting though ????
I got an error as invalid qualifier. For that i used
; and got no error.
Finally i have reached till converting my no. in desired base; but now the problem is my output is stored in an array of string and i dont know how will i print it in VB.
I used print statement; nothing happened, compiler didnt even show the error message, but nothing happened as well.
I want the output in text2.text(a text box), so i directly used a for loop.
Right now my desired number is in reminder....
But still its not working, data type of both text2.text and reminder which is an array is string.
Can someone spot what should be the changes? - k = j - 1
-
For i = 0 To j - 1
-
Text2.Text = reminder(k)
-
k = k - 1
-
Next i
I used Debug.Print as well; but its printing the number in debugger.
This is quite important to me.
Someone if knows tell me how to print an array in text box
I even tried to convert an array in string using Join but; it was giving random answers...... I need to know how do we display an array in Textbox.. Can someone tell me?
I have something to say about this code: -
For i = 0 To 9
-
If (inno(i) >= 0 And inno(i) <= 9) Then
-
This was really weird, because you can't input anything else than a 10-digit number. I guess you need an array.
An array is created like this:
Dim numbers(0 To 9) As Integer
EDIT: Oh, and to answer your question, use something like this: -
For i = 0 To 9
-
Text2.Text = Text2.Text & Array(i)
-
Next
-
Hope this helps you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ron Adam |
last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone
here for a great programming language.
Below is my first Python program (not my first program) and I'd
apreciate any...
|
by: Pieter Provoost |
last post by:
Hi,
I just made my first c++ program, and I would like to know if there are
things I can do better. Also, the exe is about 500 kb, can I make it
smaller?
Thanks!
Pieter
|
by: hokiegal99 |
last post by:
Hi Guys,
This is my first C program. I started programming in Python. Please look
over this source and let me know if I'm doing anything wrong. I want to
start out right with C, so if you see...
|
by: Todd |
last post by:
I am curious of the origins of the "Hello World" program. Who was the
first to make this popular? That is, where did it start? I did some
Google search and did not find an answer. Was it...
|
by: cj |
last post by:
Thanks to everyone that has helped me. Now I'm trying to write my first
program. I have an example of one that I need to write about. Any help
getting me started is appreciated. I'm having trouble...
|
by: mwt |
last post by:
Hello. Today I wrote my first program in C. It adds up the elements in
an array. I am just beginning to learn this language. Any tips or
pointers about better ways to write/structure/format/etc....
|
by: Martin Joergensen |
last post by:
Hi,
I wanted to try something which I think is a very good
exercise... I read in data from the keyboard and store them in a
structure. There's a pointer called "data_pointer" which I use to...
|
by: Chris Lasher |
last post by:
Hi all,
I have a simple script:
---
#!/usr/bin/env python
a = 1
b = 2
|
by: cs |
last post by:
Hi,
I'm new to C and would appreciate any feedback on the following
program, asplit, which splits a file into 2 new files, putting a
certain number of lines in the first file, and all the rest...
|
by: Fritjolf |
last post by:
Hi.
I've got a strange problem...
I've made a simple program to test encryption/decryption.
I use Rijndael encryption and here are the most important properties.
RijndaelManaged cipher =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |