electronics program

Electronics Computer Programming Q&A
Post Reply
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

electronics program

Post by Mike »

I am writing a program in VB5 Pro that assists in electronic design by giving values of resistors, coded caps, calculating coils, etc. and am currently on the resistor part. It has a drawing of a resistor created with the shape tool, and then 3 drop down boxes. In each of the boxes is a list of colors. The user selects a color then the program displays it's value in the box below. I also need the color of the identification stripes to change with the number. But when I use shape2.fillcolor = a color number, nothing happens. If anybody can help, I will e-mail the form file.
Thanks, Mike
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: electronics program

Post by greg123 »

How is the color specified? Did you use vbColor or #XXXXXX?
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: electronics program

Post by greg123 »

Ok,
Fillcolor will not work by itself as you must specify the fillstyle first.<p>shape1.fillstyle = 0 'for solid fill
shape1.fillcolor = vbBlack 'black color<p>
I will post the code.<p>greg
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: electronics program

Post by greg123 »

Mike, <p>Check out the following code:<p>
Private Sub Form_Load()<p>'Following is for the first combo box which is first color band on resistor
Combo1.AddItem "Black"
Combo1.AddItem "Brown"
Combo1.AddItem "Red"
Combo1.AddItem "Orange"
'add the other colors as above
Text1.Text = ""<p>End Sub<p>
'Following code will place the color name in the text box and
'color your shape according to the color chosen
Private Sub Combo1_Click()<p>If Combo1.Text = "Black" Then
Text1.Text = 0
Shape1.FillStyle = 0
Shape1.FillColor = vbBlack
Else
If Combo1.Text = "Brown" Then
Text1.Text = 1
Shape1.FillStyle = 0
Shape1.FillColor = &H80&
Else
If Combo1.Text = "Red" Then
Text1.Text = 2
Shape1.FillStyle = 0
Shape1.FillColor = vbRed
Else
If Combo1.Text = "Orange" Then
Text1.Text = 3
Shape1.FillStyle = 0
Shape1.FillColor = &H80FF&
'Add the other colors as above
'You can specify vbColor for the following 8 colors
'vbBlack, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta, vbCyan and vbWhite
'For the other colors you must use their Hex value which can be obtained
'from the palette
End If
End If
End If
End If
'Remember to close all If statements<p>End Sub<p>
'Following code will change the color based on the input value to the text box.
Private Sub Text1_Change()<p>If Text1.Text = "0" Then
Combo1.ListIndex = 0
Shape1.FillStyle = 0
Shape1.FillColor = vbBlack
Else
If Text1.Text = "1" Then
Combo1.ListIndex = 1
Shape1.FillStyle = 0
Shape1.FillColor = &H80&
Else
If Text1.Text = "2" Then
Combo1.ListIndex = 2
Shape1.FillStyle = 0
Shape1.FillColor = vbRed
Else
If Text1.Text = "3" Then
Combo1.ListIndex = 3
Shape1.FillStyle = 0
Shape1.FillColor = &H80FF&
'Add the other colors as above
End If
End If
End If
End If<p>End Sub<p>
With this code the user can enter any number in to the text box. If you want to restrict the values that can be entered, i.e. 1-9 add this code to your form:<p>Private Sub Text1_KeyPress(KeyAscii As Integer)<p>If IsNumeric(Chr(KeyAscii)) = True Then Exit Sub
If KeyAscii = vbKeyBack Then Exit Sub
KeyAscii = 0<p>If Len(Text1.Text) > 1 Then
MsgBox "Must be only 1 digit!"
Cancel = True
Exit Sub
End If<p>End Sub<p>
This will only allow numbers and if the user enters more than one digit, they will get a error box.<p>Greg<p>[ July 27, 2003: Message edited by: Greg ]</p>
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: electronics program

Post by Mike »

I was trying to get this to work, so I used stripe1.fillcolor = vbBlack. That worked for most, but there was not brown, and about 5 other colors. Also, most of the vb colors weren't the correct shade, so I looked in the help file and found the rgb command. so, I opened paint, then selected Edit Colors from the menu, then define custom colors. I used the multicolored rectangle to find the correct r, g and b levels, then copied them into my program. For example, stripe1.fillcolor = rgb(71, 238, 30) would make the shape stripe1 lime green. I will send you the entire program and the source code once it is finished. <p>Thanks, Mike
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: electronics program

Post by greg123 »

MIke,<p>Just to clarify, everything is ok? Does my code work?<p>Any more questions? <p>I'd love a copy of the program when its done.<p>greg
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: electronics program

Post by Mike »

Greg,
I ended up not using the code you gave, I figured it out before you responded. Thanks for the help, though. I used the command rgb and vb to get the colors correct. The code looks like this:<p>If combo1 = "Black" then
color1 = 1
stripe1.fillcolor = vbBlack
elseif combo1 = "Brown" then
color1 = 2
stripe1.fillcolor = rgb( , , )
...
end if
label1.caption = color1.<p>I'm not sure of the value for brown using rgb, but I found it using define custom color in paint.<p>Then the program goes on to calculate the value in ohms, Kohms, tolerance, max and min resistance in ohms and kohms. Then, a print option allows you to print a picture of the resistor, and the data collected and calculated.<p>This program is going to be part of a program called elecroCALC, which is a collection of electronics programs, for resistors, capacitors, coils, active crossovers, etc. So far, I only have the resistor part done. It is on a different computer, so I will e-mail you the source and compiled program tomarrow. I am planning to sell the entire collection, electroCALC on my website, which brings me to my next question, is there a way to accept credit card orders on my site for free? I need it to be secure, and don't wan't to invest much money into this. <p>Thanks, Mike
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: electronics program

Post by greg123 »

Mike,

No trouble. I'd be glad to help you out on the programming aspect of your application. Just mention me in the about menu.... :) <p>No about the digital certificate. I do not think so. The digital encryptions are paid for, as in a company is paid to sign off that a site is secure. Then there certificate is placed on the page. You can just leave an email address and have the customer email you the CC info.<p>I'll check further...<p>greg
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: electronics program

Post by Mike »

Well, I guess I cannot use credit cards, but I will make sure you are mentioned in the about menu!!!! How would you like to be addressed?<p>-Mike<p>[ July 30, 2003: Message edited by: mikea1962375 ]</p>
greg123
Posts: 361
Joined: Sat Sep 07, 2002 1:01 am
Location: St. John's NFLD Canada
Contact:

Re: electronics program

Post by greg123 »

How bout this.....<p>Greg Davis B. Eng.
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests