Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1470 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     .NET and MSSQL :

Salathe! VB Help Please!

Thread title: Salathe! VB Help Please!
Closed Thread    
    Thread tools Search this thread Display Modes  
03-05-2007, 07:37 PM
#1
Jack Morrison is offline Jack Morrison
Jack Morrison's Avatar
Status: Member
Join date: Dec 2005
Location: Ontario, Canada
Expertise:
Software:
 
Posts: 264
iTrader: 0 / 0%
 

Jack Morrison is on a distinguished road

Send a message via AIM to Jack Morrison Send a message via MSN to Jack Morrison Send a message via Yahoo to Jack Morrison Send a message via Skype™ to Jack Morrison

  Old  Salathe! VB Help Please!

I'm not asking you to do them for me necessarily, but I could use a little help on this assignment due to time constraints - I've got Questions 1 and 3 down, but these 2 are giving me some trouble. I'm working on Question 2 still, but I'm growing frustrated.

QUESTION 2 (10 marks)

The four-digit number 3025 has the following magic property: if the number formed by considering only the first two digits (30) is added to the number formed by considering only the last two digits (25), (the total will be 55), and if this number (55) is squared, the result will be the original number.

Write a Visual Basic program to find all four-digit numbers having this property and test it in the computer. Give the subroutine the name <Your Initials> A3Q2
e.g John Doe -> Sub JDA3Q2(


QUESTION 4 (10 marks)

Write a Visual Basic program to find all positive integers less than 1000 which do not end in zero and have the property that if the rightmost digit is deleted, the integer obtained divides into the original evenly. For example, 39 is such an integer since 3 remains after deleting the rightmost digit and 3 divides 39 evenly.
Give the subroutine the name <Your Initials> A3Q4 ( e.g John Doe -> Sub JDA3Q4( ) )

03-05-2007, 07:52 PM
#2
Jack Morrison is offline Jack Morrison
Jack Morrison's Avatar
Status: Member
Join date: Dec 2005
Location: Ontario, Canada
Expertise:
Software:
 
Posts: 264
iTrader: 0 / 0%
 

Jack Morrison is on a distinguished road

Send a message via AIM to Jack Morrison Send a message via MSN to Jack Morrison Send a message via Yahoo to Jack Morrison Send a message via Skype™ to Jack Morrison

  Old

This is what I have for Question 2 - I feel it could be greatly improved though :/ - I still also have no way to check for all 4 digit numbers that do this.

Code:
Option Explicit
'Written By Jack Morrison

Sub JMA3Q2()
Dim N0 As Integer
Dim N1 As Integer
Dim N2 As Integer
Dim Total As Integer
Dim Ftotal As Integer
Dim Success As Boolean

N0 = InputBox("Enter Your 4 Digit Number", "Magic Number Calculator")
N1 = InputBox("Enter the first 2 digits of the number", "Magic Number Calculator")
N2 = InputBox("Enter the second 2 digits of the number", "Magic Number Calculator")
Total = N1 + N2
Ftotal = Total ^ 2

If Ftotal = N0 Then
Success = True
Else
Success = False
End If

If Success = True Then
MsgBox ("This number is a magic number: " & N0)
ElseIf Success = False Then
MsgBox ("This Number is not a Magic Number: " & N0)
End If


End Sub

03-07-2007, 03:37 PM
#3
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

Here's what I would do in PHP, it's automated..
PHP Code:
for($i 1000$i 10000$i++)
{
       
$first strpos($i02);
       
$last strpos($i22);
       
$sum $first $last;
       
$result $sum $sum;
       if (
$result == $i)
       {
             
"The number ".$i." is magic.\n";
       }

If it's possible in VB, run a for loop from numbers 1000-9999, and then just do the math, and then use a if statement to see if the result is equal to the number inputted via the for loop, if it is equal, then output it's magic, and then if not, don't do anything (otherwise it will use more resources and it would be hard to see which are magic). Hope this helps.

Also, for the second this is what I would do in PHP:
PHP Code:
for($i 1$i 1000$i++)
{
      
$first_digits strpos($i0strlen($i) - 1); // take of last digit
      
if(($i $first_digits) == 0// modulus operation (operation gives remainder after dividing first number with second number)
      
{
             echo 
$i." is a magic number"// echo number
      
}

Just run a for loop from 1-1000, and then take off the last digit. Then, if POSSIBLE in VB, use modulus to see if there is a remainder. If VB doesn't have modulus, then you can divide the number from the for loop by the number after the last digit is taken off, and then check for a '.' in the string to see if its a decimal, if not then ouput the number as magic. Again, hope this helps.

03-07-2007, 09:15 PM
#4
masfenix is offline masfenix
Status: Member
Join date: Mar 2006
Location: t.dot canaada
Expertise:
Software:
 
Posts: 182
iTrader: 1 / 100%
 

masfenix has a little shameless behaviour in the past

Send a message via AIM to masfenix

  Old

axiom you should try converting andrew's php code, to vb. and if you cant, paste whatever you have and ill help you.

but i hate helping people with school projects

12-02-2007, 05:49 PM
#5
vbguru is offline vbguru
Status: I'm new around here
Join date: Dec 2007
Location:
Expertise:
Software:
 
Posts: 3
iTrader: 0 / 0%
 

vbguru is on a distinguished road

  Old

This is what I have for Question 2 - I feel it could be greatly improved though :/ - I still also have no way to check for all 4 digit numbers that do this.

[CODE]Option Explicit
'Written By Jack Morrison

Sub JMA3Q2()
Dim N0 As Integer
Dim N1 As Integer
Dim N2 As Integer
Dim Total As Integer
Dim Ftotal As Integer
Dim Success As Boolean

N0 = InputBox("Enter Your 4 Digit Number", "Magic Number Calculator")
N1 = InputBox("Enter the first 2 digits of the number", "Magic Number Calculator")
N2 = InputBox("Enter the second 2 digits of the number", "Magic Number Calculator")
Total = N1 + N2
Ftotal = Total ^ 2

(i think this is miner improvement than before )
If Ftotal = N0 Then
Success = True
MsgBox ("This number is a magic number: " & N0)
Else
Success = False
MsgBox ("This Number is not a Magic Number: " & N0)
End If

End Sub

if i can send you my variation of this programme ?

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed