11 Replies - 1659 Views - Last Post: 21 March 2013 - 01:16 AM Rate Topic: -----

#1 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 109
  • Joined: 28-February 13

problem with multiply

Posted 16 March 2013 - 10:57 AM

I have one simple form where the results must be numbers of a lines in word, and input data is dimension of the text in Word, margin(in inches/centimetres) and size of a text.
Problem is, when I put data in dimension, for example 31.5 and want to go in milimetres, is shown 3150, not 315. I assume, that problem is because I work with a strings
Text1.Text = Text1.Text * 10

but, when I put CDbl, result is the same.
What can cause the problem?

Is This A Good Question/Topic? 0
  • +

Replies To: problem with multiply

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,447
  • Joined: 12-December 12

Re: problem with multiply

Posted 16 March 2013 - 11:07 AM

It would help if you showed your use of CDbl, but perhaps you are doing:

Text1.Text = CDbl(Text1.Text * 10)    'rather than
Text1.Text = CDbl(Text1.Text) * 10

Was This Post Helpful? 0
  • +
  • -

#3 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 109
  • Joined: 28-February 13

Re: problem with multiply

Posted 16 March 2013 - 01:51 PM

Not work again. It is the same. 29.7->2970.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,447
  • Joined: 12-December 12

Re: problem with multiply

Posted 16 March 2013 - 01:55 PM

View Postmercy_angel, on 16 March 2013 - 01:51 PM, said:

Not work again. It is the same. 29.7->2970.

So it appears you are multiplying by 100.. or multiplying by 10 twice..

Post your relevant code, wrapped in CODE tags - it tells you how to do this directly in the area where you will be typing your post.

This post has been edited by andrewsw: 16 March 2013 - 01:56 PM

Was This Post Helpful? 0
  • +
  • -

#5 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 109
  • Joined: 28-February 13

Re: problem with multiply

Posted 16 March 2013 - 04:59 PM

Option Explicit

Private Sub Command1_Click()
End
End Sub

Private Sub Option1_Click()
Text1.Text = CDbl(Text1.Text / 10)
Text2.Text = CDbl(Text2.Text / 10)
End Sub

Private Sub Option2_Click()
Text1.Text = CDbl(Text1.Text * 10)
Text2.Text = CDbl(Text2.Text * 10)
End Sub

Private Sub Command2_Click()
If Option5.Value = True Then
Label9.Caption = CInt((Text2.Text - (Text3.Text * 2.54) - (Text6.Text * 2.54)) / ((Text7.Text / 72) * 2.54))
ElseIf Option6.Value = True Then
Label9.Caption = CInt((Text1.Text - (Text4.Text * 2.54) - (Text5.Text * 2.54)) / ((Text7.Text / 72) * 2.54))
Else
End If
If Option2.Value = True And Option3.Value = True Then
Label9.Caption = CInt((Text1.Text - (Text4.Text * 2.54) - (Text5.Text * 2.54)) / ((Text7.Text / 72) * 2.54)) / 10 / 3.68448275862069
End If
End Sub
Private Sub Option3_Click()
Text3.Text = Text3.Text * 2.54
Text4.Text = Text4.Text * 2.54
Text5.Text = Text5.Text * 2.54
Text6.Text = Text6.Text * 2.54
End Sub

Private Sub Option4_Click()
Text3.Text = Text3.Text / 2.54
Text4.Text = Text4.Text / 2.54
Text5.Text = Text5.Text / 2.54
Text6.Text = Text6.Text / 2.54
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then
Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub



Private Sub Text2_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then
Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub


Private Sub Text3_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then
Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then
Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then

Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub



Private Sub Text6_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then
Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub


Private Sub Text7_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeyBack Or KeyAscii = 46 Then
Else
KeyAscii = 0
Beep
MsgBox " Samo su brojevi dozvoljeni ", vbCritical, "Greska"
End If
End Sub



Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3617
  • View blog
  • Posts: 12,447
  • Joined: 12-December 12

Re: problem with multiply

Posted 16 March 2013 - 05:06 PM

I've already pointer out the flaw in your approach in post #2:

CDbl(Text1.Text / 10)    'should be
CDbl(Text1.Text) / 10

You are currently attempting to divide "some text" by a number.

I see also that you haven't renamed any of your controls/objects :whistling: or indented your code.

This post has been edited by andrewsw: 16 March 2013 - 05:08 PM

Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: problem with multiply

Posted 17 March 2013 - 12:49 PM

You could cut your code size in half if you learned how to use control arrays, and it isn't difficult.
Was This Post Helpful? 0
  • +
  • -

#8 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 109
  • Joined: 28-February 13

Re: problem with multiply

Posted 17 March 2013 - 02:26 PM

Sorry, it's a old code,
Text1.Text = CDbl(Text1.Text) * 10
won't work.
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: problem with multiply

Posted 17 March 2013 - 11:01 PM

Hold on a minute. Let's take your line 8. Let's say that you have the value 31.5 in Text1.text. Are you telling me that when you execute line 8, the number 3150 shows in it? CDbl won't change anything in this line, by the way. It will still be a string when you assign it to the Text property.
Was This Post Helpful? 0
  • +
  • -

#10 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 109
  • Joined: 28-February 13

Re: problem with multiply

Posted 18 March 2013 - 12:59 AM

View PostBobRodes, on 17 March 2013 - 11:01 PM, said:

Hold on a minute. Let's take your line 8. Let's say that you have the value 31.5 in Text1.text. Are you telling me that when you execute line 8, the number 3150 shows in it? CDbl won't change anything in this line, by the way. It will still be a string when you assign it to the Text property.


Yes that's right. But how to write to work?
Was This Post Helpful? 0
  • +
  • -

#11 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: problem with multiply

Posted 20 March 2013 - 08:19 PM

I'm sorry, but I don't believe you. You're telling me that VB is multiplying a number by 100 when it's actually being told to multiply by 10. Much more likely is that you're wrong.
Was This Post Helpful? 0
  • +
  • -

#12 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: problem with multiply

Posted 21 March 2013 - 01:16 AM

I agree with everyone else in regards to the maths, but I am curious as to how you drive your program. Please explain what you do to create the output you get.

Is that your full code shown above?

If it is, then the only way I can see that you could get the results you get is by clicking the option1 or option2 control twice, or the click event is being fired somewhere else as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1