Click here to Skip to main content
15,900,378 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHelp required regarding the Network down/Database down issue in VB6 Pin
nsurendran13-Aug-07 1:04
nsurendran13-Aug-07 1:04 
QuestionRTF files manipulation without using builtin controls Pin
misaw7513-Aug-07 0:25
misaw7513-Aug-07 0:25 
QuestionHow to make certain Columns in a datagrid Read only in vb.net Pin
Vimalsoft(Pty) Ltd12-Aug-07 23:54
professionalVimalsoft(Pty) Ltd12-Aug-07 23:54 
AnswerRe: How to make certain Columns in a datagrid Read only in vb.net Pin
i gr813-Aug-07 7:54
i gr813-Aug-07 7:54 
GeneralRe: How to make certain Columns in a datagrid Read only in vb.net Pin
Vimalsoft(Pty) Ltd14-Aug-07 22:59
professionalVimalsoft(Pty) Ltd14-Aug-07 22:59 
QuestionReduce size of avi file Pin
Rupesh Kumar Swami12-Aug-07 22:42
Rupesh Kumar Swami12-Aug-07 22:42 
AnswerRe: Reduce size of avi file Pin
Christian Graus12-Aug-07 23:57
protectorChristian Graus12-Aug-07 23:57 
QuestionHELP - SIMPLE MATH PROBLEM Pin
cyndy_northrup12-Aug-07 22:05
cyndy_northrup12-Aug-07 22:05 
HELP - SIMPLE MATH PROBLEM

Hey people!


Have what should be a simple math problem, but its driving me absolutely buggy!

Something ridiculously obvious is escaping me and I can't for the life of me figure out
what the heck it is.

So, I describe what Im trying to do in this email and have also included what I think are the most
important code snips below, where I think the error is occuring.

So here is the description of the problem.


A series of numbers are provided by the user. The series is a sequence that is variable in
length and variable in size per number. For example

23 1 899 72 11 02

or

1 7 8 19 2

or

233 455 23 24 29 12 14 16 17 91 92 94 98 57 34


so any number can be any size, and there can be any number within the sequence

The numbers are entered by the user into a text box

The user clicks a command button

A routine enumerates the total number of individual numbers in the sequence and
creates an array having the same number of elements that will correspond to the
math we will perform, and that follows the following parameter of;
(Code shown that creates the proper number of array elements)

Where "prefix_number" = the total number of numbers in the sequence, i.e. for the second
example above ( 1 7 8 19 2), prefix_number = 5

'this line determines the total number of array elements required
array_total_elements = (prefix_number + 1) * ((prefix_number + 1) + 1) / 2

'--------------------
'april 19 - 06 - ReDim adding_array(numchars) 'array with the number of elements of the same amount as the number of chars
'this array forms the needed structure of the conic, creating all positions for number placement within the cone

ReDim adding_array(array_total_elements)
'--------------------

So now we have an array with a total number of elements that will accomodate the math we want to perform
on the sequence, and that math operation is this;

Take the given sequence, i.e.

1 7 8 19 2

where each number in the sequence is stored individually in an array element, and subtract it from its neighbor to its immediate
left and starting from the left hand side, take the resultant of that value and place it in the appropriate array element not as yet occupied
and continue the process.

So here we have the following


1 7 8 19 2 is processed as;

where

1 is stored in array element 0
7 is stored in array element 1
8 is stored in array element 2
19 is stored in array element 3
2 is stored in array element 4


2-19 = -17

19-8 = 11

8-7 = 1

7-1 = 6



so now we have ;

1 7 8 19 2
6 1 11 -17

and 6, 1, 11, -17 are stored in array elements

6 is stored in array element 5
1 is stored in array element 6
11 is stored in array element 7
-17 is stored in array element 8

we continue as;


6 1 11 -17


-17-11 = -28

11-1 = 10

1-6 = -5



and -28,10,-5 are stored in array elements

-5 is stored in array element 9
10 is stored in array element 10
-28 is stored in array element 11


And so on, the process continuing until we cant do it any more and we arrive at the last
array element result.

Then, we simply dump all the array values in proper sequence to a text box, perhaps a rich text box
and we place a hard return CHR(13) after each sub sequence so we can view the proper order of
computation.


So the box shows something like;

1 7 8 19 2
6 1 11 -17
-28,10,-5
....and so on.


Seems simple enough to me, but for some reason the whole backwards processing thing has stumped me,
working from left to right, subtractively, especially with properly populating and working with the arrays
that way, sounds silly I know, but I can't get this to work.

My code snippets follow below, can anyone whip this together simply, quickly?

Thanks for any feedback!

Cyndy















'====================================='May 12 - 07
'this line modified to cause backwards subtractive process in line
'LAST CODED
check_what_it_is = Val(adding_array(adding_element))
check_what_it_is2 = Val(adding_array(adding_element - 1))
adding_var = Val(adding_array(adding_element)) - Val(adding_array(adding_element - 1))
'====================================='May 12 - 07
DoEvents


'=======================
' may 12 07
'===================
'value placement
adding_array(adding_element + array_pos_update) = adding_var
adding_element = adding_element - 1
'--------------
'may 29-07

'bug occurs here, adding element gets reduce to zero and it needs to
'go back up to the rung down

Debug.Print "adding_array(6) ;"; adding_array(6)
'here is where it breaks down, at the row switcher
Debug.Print "adding_array(12) ;"; adding_array(12)
'=======================

'======for display to text boxes only, captures data stream for display

string_result = text_trans & " " & string_result
text_trans = CStr(adding_var) & " " & text_trans
'======for display to text boxes only, captures data stream for display

'bug occuring here, may 29-07, its not switching to the next row properly

If row_switch_counter = switch_to_new_row Then

array_pos_update = array_pos_update + times_through_the_loop 'APRIL 18-06, does this var need to be reset to zero
adding_element = times_through_the_loop '- 1 'array_pos_update 'moves array position pointer ahead two, jumping to next line
Debug.Print "adding_element ;"; adding_element
'may 28 - 7 ===============

'may 28 - 7 switch_to_new_row = switch_to_new_row - 1
row_switch_counter = times_through_the_loop
text_trans = text_trans & Chr(13)

times_through_the_loop = 0
End If
End If

Next q 'steps through for loop
'===============================
'===============================
'=== ADDING ARRAY ENDS
'===============================
'==============================
'-----------


ctr_transfer = 0

RichTextBox3.Text = display_first_Line & Chr(13) & text_trans

'-------- send array info to text box

set_carriage_returns = prefix_number + 1
check_for_carriage_returns = 0

feedtextbox_ctr = 0
adding_element = 0
display_result = "" 'var to hold looped array numbers

Do Until feedtextbox_ctr = numchars

DoEvents

display_result = display_result & adding_array(adding_element)
If check_for_carriage_returns = set_carriage_returns Then
display_result = display_result & Chr(13)
set_carriage_returns = set_carriage_returns - 1
check_for_carriage_returns = 0
End If

check_for_carriage_returns = check_for_carriage_returns + 1
feedtextbox_ctr = feedtextbox_ctr + 1
adding_element = adding_element + 1

Loop
'-------- send array info to text box

Text2.Text = display_result
'Text2.Text = text_trans







AnswerRe: HELP - SIMPLE MATH PROBLEM Pin
Christian Graus12-Aug-07 23:56
protectorChristian Graus12-Aug-07 23:56 
AnswerRe: HELP - SIMPLE MATH PROBLEM Pin
Luc Pattyn13-Aug-07 0:50
sitebuilderLuc Pattyn13-Aug-07 0:50 
Questioncrystal reports Pin
Sonia Gupta12-Aug-07 19:05
Sonia Gupta12-Aug-07 19:05 
AnswerRe: crystal reports [modified] Pin
i gr812-Aug-07 22:50
i gr812-Aug-07 22:50 
QuestionPlease I need Help Pin
Agbe12-Aug-07 12:52
Agbe12-Aug-07 12:52 
AnswerRe: Please I need Help Pin
Guffa12-Aug-07 13:53
Guffa12-Aug-07 13:53 
QuestionShow "My Computer on the desktop" Pin
dave/chicago/dc12-Aug-07 12:30
dave/chicago/dc12-Aug-07 12:30 
AnswerRe: Show "My Computer on the desktop" Pin
Dave Kreskowiak12-Aug-07 15:42
mveDave Kreskowiak12-Aug-07 15:42 
GeneralRe: Show "My Computer on the desktop" Pin
dave/chicago/dc18-Aug-07 3:52
dave/chicago/dc18-Aug-07 3:52 
QuestionMail Message Pin
md_refay12-Aug-07 6:44
md_refay12-Aug-07 6:44 
AnswerRe: Mail Message Pin
Luc Pattyn12-Aug-07 6:53
sitebuilderLuc Pattyn12-Aug-07 6:53 
Questioncalling a computer on lan using microphone? Pin
crispin_code12-Aug-07 6:22
crispin_code12-Aug-07 6:22 
AnswerRe: calling a computer on lan using microphone? Pin
Dave Kreskowiak12-Aug-07 7:49
mveDave Kreskowiak12-Aug-07 7:49 
Questioncalling a computer on lan using microphone Pin
crispin_code12-Aug-07 6:21
crispin_code12-Aug-07 6:21 
AnswerRe: calling a computer on lan using microphone Pin
DanB198315-Aug-07 11:15
DanB198315-Aug-07 11:15 
QuestionCrystalPreport VS VB Pin
Assaf8211-Aug-07 21:09
Assaf8211-Aug-07 21:09 
QuestionPrevent change current row .. DataGridView ? Pin
kindman_nb11-Aug-07 18:41
kindman_nb11-Aug-07 18:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.