Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 11th, 2005, 09:30 AM
Kage Musha Kage Musha is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 Kage Musha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Some pseudo code translation into VBA

I'm in a pinch right now, I'm familiar with php and java but my problem now is that I got this code which needs to be translated into VBA (access)

I've translated abit already but I'm stuck now.

I've got this pseudo code to translate
PHP Code:
/* DON'T FORGET THAT THIS IS PSEUDO-CODE ITS NOT VB OR VBA !!! MORE LIKELY SOMETHING LIKE JAVA / PHP 
   It just tells you, what you should do to achieve what you want!*/

int no_choices=4;    //the number of choices each student has
int max_courses=2;    //the number of courses a stundent is allowed (and has to) select

for(int p=0;i<no_choices;p++)
{
    
mysql_query("SELECT _fd_id, choice" " FROM N_Data_Tbl");

    
int     no_rows mysql_num_rows();    

    
int    all_fd_ids[no_rows];    //Array of all _fd_id's
    
String     all_choices[no_rows];    //Array of Strings to save all 'p' choices...
    
    
for(int i=0;i<no_rows;i++)    //this fills the arrays with the data from the query
    
{
        
all_fd_ids[i]  = mysql_result(i,0);
        
all_choices[i] = mysql_result(i,1);    
    }

    for(
int i=0;i<no_rows;i++)
    {
        
mysql_query("SELECT MaxStudents FROM Course WHERE CourseName = '" all_choices[i] + "'");
        
int MaxStudents mysql_result(0,0);
        
mysql_query("SELECT * FROM Rel_SelectedCourses WHERE CourseName = '" all_choices[i] + "'");
        if (
MaxStudents mysql_num_rows())    // if there are free places left (the maximum number of stundents is higher then the number of stundents which are assigned to the course) assing the student to the course
        
{
            
mysql_query("SELECT * FROM Rel_SelectedCourses WHERE _fd_id=" all_fd_ids[i]);
            if (
mysql_num_rows()<max_courses)
            {
                
//the following line inserts 1 line to the Rel_SelectedCourses table containing the currently selected student and choice (selected by the index "i")
                
mysql_query("INSERT INTO Rel_SelectedCourses (_fd_id, CourseName) VALUES (" all_fd_ids[i] + ", '" all_choices[i] +"')";
            }
        }
    }
}


////////////////////////////////  OUTPUT ROUTINE  ///////////////////////////

int max_courses=2;    //should be a global variable

mysql_query("SELECT _fd_id, gname, iname, lname FROM N_Data_Tbl ORDER BY _fd_id");

int no_rows mysql_num_rows();

int     all_fd_ids[no_rows];    //Array of all _fd_id's
String     all_names[no_rows][3];    //2-dimensional Array, to save all needed strings... in this case names

for(int i=0;i<no_rows;i++)    //fills the upper arrays
{
    
all_fd_ids[i] = mysql_result(i,0);
    
all_names[i][0] = mysql_result(i,1);                
    
all_names[i][1] = mysql_result(i,2);                
    
all_names[i][2] = mysql_result(i,3);                
}

String    selected_courses[no_rows][max_courses];

for(
int i=0;i<no_rows;i++)
{
    
mysql_query("SELECT * FROM Rel_SelectedCourses WHERE _fd_id=" all_fd_ids[i] + " ORDER BY _fd_id");
    
num_rows=mysql_num_rows();
    for(
p=0;p<num_rows;p++)
    {
        
selected_courses[i][p]=mysql_result(1,p);
    }
}

//we have filled all arrays now with the data we need to achieve the following output:
// gname | iname | lname | course1 | course2

for(int i=0;i<no_rows;i++)
{
    print 
all_names[i][0];
    print 
all_names[i][1];
    print 
all_names[i][2];
    for(
p=0;p<max_courses;p++)
    {
        print 
selected_courses[i][p];
    }
    print 
endline;
}

//Ofcourse you will have to put this in a table instead... this is kept dynamic, so that you are able to change the number of courses for each stundent, if you don't need this you can still keep it - it also works for 2 courses well ;)


 
example for JOIN"SELECT N_Data_Tbl.gname, N_Data_Tbl.iname, N_Data_Tbl.lname, Rel_SelectedCourses.CourseName FROM N_Data_Tbl, Rel_SelectedCourses WHERE N_Data_Tbl._fd_id=Rel_SelectedCourses._fd_id" <--- would be a possible but bad join.... doesn't give it well formated 


and I've translated this so far
PHP Code:
Private Sub Command26_Click()
Dim cnn As Connection
Dim strSQL 
As String
Dim no_rows
Dim no_choices
max_coursespAs Integer
Dim Recordset 
As New ADODB.Recordset

    no_choices 
4   'the number of choices each student has
    max_courses = 2  '
the number of courses a stundent is allowed (and has toselect p 0
    
Do While <= no_choices
         p 
1
    
    Set cnn 
CurrentProject.Connection

    Set Recordset 
Command.Execute("SELECT _fd_id, choice" " FROM N_Data_Tbl")
    
Set no_rows Command.Execute("SELECT COUNT(*) FROM N_Data_Tbl")
 

    
ReDim all_fd_ids(no_rows) As Integer 'Array of all _fd_id's
    ReDim all_choices
(no_rows) As String 'Array of Strings to save all 'p' choices...

    i = 0
    Do While i <= no_rows '
this fills the arrays with the data from the query
        i 
1
       all_fd_ids
(i) = Recordset(i0)
       
all_choices(i) = Recordset(i1)
    
Loop
    Loop
   

End Sub 

I'm having trouble with the recordsets and more what lies beneath
Anyone so kind to help me here?

Reply With Quote
  #2  
Old January 11th, 2005, 11:36 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
First you will need to decide which database engine you are going to use, either DAO or ADO. In your translation above you are using both, which won't work. Each has their own specific syntax and database engines for writing code. Example:

DAO
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select fields FROM table", dbOpenDynaset)

ADO
Dim objConn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set objConn = CurrentProject.Connection
rs.Open "Select fields FROM table, objConn, adOpenKeySet

Once you decide which one you will be using, utilize the built in help menus to help build the correct syntax for each code snippit. Also avoid using names like Recordset for the names of your variables. Those are Intrinsic Constants used by Access and should be avoided. Standard naming conventions apply to variables in the same way they do to object names. Also each Dim statement should be declared otherwise Access will treat it as a Variant data type by default.

Hopefully this will give you a start.
lwells

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Some pseudo code translation into VBA


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT