Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Code optimization & dll query


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2008, 11:29 PM
Newbie
 
Join Date: Mar 2008
Posts: 8
Default Code optimization & dll query

Hi all, first off - ive only had basic4ppc for about 4 days, but im really loving it. That me onto my forth program now - so i think i'll be buying the full program soon. I work in a petrol station, and find that when its quiet i can sit and do my programming without any problems, really does make the days go by quicker .

Anyway back on topic.

I have wrote a bit of code, but it takes too long to run (well about 10 seconds) I know that what i want can be done almost instantly but i dont have my thinking cap on.

Can anyone optimize this code for me, either by shifting bits, multiplication or whatever.

Code:
dim tmpcode(3)
dim codecount,loopa,loopb,inputnum

tmpcode(0)=1
tmpcode(1)=1
tmpcode(2)=1
tmpcode(3)=1

inputnum = *****a number between 0 and 1023*****

for loopa = 0 to codecount - 1
 tmpcode(3) = tmpcode(3) + 1
 for loopb = 3 to 1 step -1
  if tmpcode(loopb) = 7 then
   tmpcode(loopb) = 1
   tmpcode(loopb - 1) = tmpcode (loopb - 1) + 1
  end if
 next loopb
next loopa

txtOutput.text = tmpcode(0) & tmpcode(1) & tmpcode(2) & tmpcode(3)
so that is the first problem.

the second is that i have a '3 step program', just now i am using panels for the different steps and hiding and showing them as needed.

the program is like this.

Step 1... choose an item from a combo box

Step 2... show the panel corresponding to the option chosen in Step 1

this panel could include combo boxes, text boxes, check boxes or whatever. clicking 'next' on this panel does a calculation on the data given in the panel, and passes it on to panel 3

Step 3... Show the result, this will be a number of indeterminate length, usually 4-8 digits


So far i have created 6 option for step 1, therefore i have 6 panel 2's, and its starting to get confusing. Im also worried about using too many controls on a single form (up to about 100 or so, so far) and i want to bump it up to around 50 options (therefore 50 panels * about 12 controls each)

I imagine that will also start to slow down the program.

It also means that i need to supply a full new program each time i make a change.

What i want to do.

I want the program to start,... then look through the app directory for DLL's, each one it finds - it interrogates, to get its name, and adds it the list in step 1.

If you choose an option, then for step 2, the THE DLL SHOWS A PANEL/FORM/WHATEVER that looks like part of the host application, when the DLL panel has been filled, it hides its panel, does its maths (different for each DLL) and returns the number for my program to display on the Step 3 page.

Is this possible to use DLLs in this way, can they be dynamically loaded at run time, can they display information in my application.

This would mean that as i develop new algorithms, i just need to send out new DLLs, or if i need to alter an algorithm, again just a replacement DLL.

Id like to add the ability to download additional DLL's over the air, then add them dynamically to the list of options.

If im going about this all wrong, please can you point me in the right direction.

Thanks

Graham
Reply With Quote
  #2 (permalink)  
Old 03-27-2008, 10:12 PM
Newbie
 
Join Date: Mar 2008
Posts: 8
Default

no takers on the code optimization??

what about the dll query, is it possible for a dll to display with a panel within my program, or can it display a box over my program??

thanks

graham
Reply With Quote
  #3 (permalink)  
Old 03-28-2008, 01:19 AM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 119
Awards Showcase
Beta Tester 
Total Awards: 1
Arrow 7 mod 7 = 0

The code optimisation:
Looks like you're using iterations to deal with the need to do maths!
I think that you're missing out on 'mod'

What does inputnum do & where does codecount come from?

Come to think of it you could probably make life simpler by avoiding the array if it's only use is to create the string at the end. Use mod & your 7 times tables (but don't forget to add 1 to the mod result, you'll get 0 when you want 1).

(The lack of a simple code solution is deliberate here, you'll hit similar problems later on - this is a good one to cut your teeth on. Little snippets of code to test the workings, as you go, will help you get the hang of it.)
Reply With Quote
  #4 (permalink)  
Old 03-28-2008, 02:25 PM
Newbie
 
Join Date: Mar 2008
Posts: 8
Default

hi thanks, i get what you mean. I will have a look at the mod command, i knew it could be done easier, but i havn't done any programming since microsoft decided to move over to .NET.


I have been programming on the windows for many years, but it was always business orientated, and no complex maths involved.

All my experience has been on VB5 and 6.

I now have have my program doing 18 algorithms, but am still using panels.


** i paraphrased the code a bit so i was only posting relevant code **
InputNum comes from either a textbox for some of the algorithms or a set of checkboxes (10 bit binary).

The reason for the array is that i use many different algorithms which do things in different ways. so i figured use an array so that my code display page runs without any modification regardless of which algorithm im using at that time.

I am having to work out my algorithms from a list of input numbers = codes, thats why my code isn't optimized, as i dont have the original algorithms used to generate the codes.

Basically i work out how the code from the input number, then try and come up with an algorithm that will solve it. Once it works i try and optimize it to work faster.

Basically on my pocket pc, and with the nature of the codes i should ALWAYS be able to calculate the code within 1 second.

i'll work on the mod thing, and post back if i solve it. thanks.

can a dll show a panel within my program??

Last edited by gangsta : 03-28-2008 at 02:55 PM.
Reply With Quote
  #5 (permalink)  
Old 03-28-2008, 02:45 PM
Newbie
 
Join Date: Mar 2008
Posts: 8
Default

just had a look in the online help, and couldn't find the MOD function, is it implimented in basic4ppc???

if not can i use this formula to simulate the mod fuction (from wikipedia):

mod(a, n) = a - n * floor(a / n)

i have substituted INT in place of floor in the hope that it will still work.
which i would impliment in code as something like:

Code:
Sub Mod (a, n)
  Return (a - n) * int(a / n)
End Sub
ive never done any crypto stuff before but most of the algorithms ive looked at so far have been not too dificult (although as seen above, a few need some optimization)
Reply With Quote
  #6 (permalink)  
Old 03-28-2008, 04:27 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,896
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by gangsta View Post
just had a look in the online help, and couldn't find the MOD function
Yes. See Help->Main Help->Basics->Operators

Quote:
can a dll show a panel within my program??
Do you mean a real dll as in a .NET assembly or native dll? What are you going to compile them with? In principle a dll can build a panel with some controls and put it on a Form specified by the main program.
Reply With Quote
  #7 (permalink)  
Old 03-28-2008, 04:30 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 812
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

Hi gangsta,
Mod is not a function but an operator, and is implemented in B4PPC.

Ex:
a = 7 mod 3 result 1
The function means 7 devided 3 equals 2 and the reminder is 1, a is the reminder
a = 7 Mod 3 result 1
a = 8 Mod 3 result 2
a = 9 Mod 3 result 0
a = 10 Mod 3 result 1
and so on.

I have added a small program you can play with.

For your example in the first post, could you explain exactly what you want to do or add some more code with an example to make it easier for others to give you any advice.

Best regards
Attached Files
File Type: sbp TestMod.sbp (895 Bytes, 0 views)
__________________
Klaus
Switzerland
Reply With Quote
  #8 (permalink)  
Old 03-28-2008, 09:52 PM
Newbie
 
Join Date: Mar 2008
Posts: 8
Default

Hi the program is for decoding.

Eg you supply it with the serial number for the device, and it applys the algorithm to it, to give the unlock code.

I have visual basic enterprise edition , can i use that for building dll's to use within basic4ppc or do i have to buy .NET (or will visual studio express work for this)

My posted code at the top of the page works perfectly for this algorithm, its just slow

i have been playing with mod, had a look at the demo, so hopefully i'll work it out shortly

thanks

Graham
Reply With Quote
  #9 (permalink)  
Old 03-28-2008, 10:54 PM
Newbie
 
Join Date: Mar 2008
Posts: 8
Smile

woohoo

thanks people, I have wrote a small base convertor based on what I found on the net, it will convert any integer to any other base, but be warned - no boundry checks - I did a stpid mistake when testing it an converted to base 1, my ppc was NOT amused - lol

thanks for pointing me in the right direction, I actually enjoy learning new things, and don't mind looking stuff up if im pointed in the right direction.

Graham

Code:
Sub convertBase(iNum, bNum)
Dim q, r, a
q = iNum
r = iNum
Do While q <> 0
 r = q Mod bNum
 q = Int(q / bNum)
 a = r & a
Loop
return a
End Sub

Last edited by gangsta : 03-29-2008 at 09:56 AM.
Reply With Quote
  #10 (permalink)  
Old 03-29-2008, 10:28 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,896
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by gangsta View Post
I have visual basic enterprise edition , can i use that for building dll's to use within basic4ppc or do i have to buy .NET (or will visual studio express work for this)
I assume that is VB 6.0 Enterprise in which case the answer is no. VS Express will not produce dlls for mobile devices but the free Sharp Develop http://www.icsharpcode.net/OpenSource/SD/ together with the free SDK from Microsoft will produce device targeted dlls (they also usually work on the dekstop). Severasl members of this forum use it, just post a request for advice (I use VS2005 Standard Edition).
Reply With Quote
Reply



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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Code giannimaione Questions & Help Needed 5 06-01-2008 07:03 PM
A query to Erel mozaharul Questions & Help Needed 5 04-28-2008 12:21 PM
Query on webbrowser.dll on HTC Touch WM6 badkarma Questions & Help Needed 8 04-11-2008 12:45 PM
Microsoft Access Query somersetrc Questions & Help Needed 2 11-29-2007 09:29 AM
Help with code cdeane Questions & Help Needed 9 09-22-2007 05:30 PM


All times are GMT. The time now is 01:13 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0