Thanks for your help. this made the parent and childs work but still kept repeating the categories. nevertheless i have decided to program this in PHP rather than vb.net. thank you
I will post again if i decide to revert back to vb.net
Hi All
I am creating a program which will (in the end) help me quickly transfer products from one category into another within a MySQL Database.
I have a database with TWO separate tables which are connected using INNER JOIN where the products have a categoryID as do the categories have categoryID fields.
I want to show, in a treeview, all of the categories and then when i 'open' a category, i can see all of the products. eventually I'll add the moving properties, sub categories etc but at the moment i just do not know how to display a parent and child properly.
I am getting this;
See Image Attachment
you can see that 35mm ... should be the parent (category) and the sony ... should be the products
and this is my code
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class Form1
Dim dbCon As MySqlConnection
Dim strQuery As String = ""
Dim SQLCmd As MySqlCommand
Dim DR As MySqlDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetDBData()
End Sub
Private Sub GetDBData()
Try
' Prepare conn and query
dbCon = New MySqlConnection("Server=localhost;Database=xxxxxxx;Uid=xxxx")
strQuery = "SELECT categories.category_name, categories.homepagevis, products.product_name " & _
"FROM categories INNER JOIN products ON categories.categoryID = products.categoryID " & _
"ORDER BY categories.category_name ASC "
SQLCmd = New MySqlCommand(strQuery, dbCon)
Dim DA As New MySqlDataAdapter(SQLCmd)
Dim DT As New DataTable()
DA.Fill(DT)
'Open db and kick of query
dbCon.Open()
DR = SQLCmd.ExecuteReader …
I am having a problem with my project in VB.NET which is a program to do facial recognition on photos sent via MMS using a GPRS modem.
I have got the facial recognition to work on photos input via the computer. the problem arises when i send the MMS over.
After opening a serial port connection, i send the image to the modem, the program recognises that an SMS is recieved containing a URL to the image and so begins a dial up procedure from the gprs modem to retrieve the image.
The GPRS modem dials up and connects for literally 1 or 2 seconds then disconnects causing my program to crash and return a 'An InvalidOperationException exception is thrown in cases when the failure to invoke a method is caused by a reason' message. this is annoying because it doesnt point to where the problem is occurring.
If i try to dial up to the gprs modem through network connections in windows, the same thing happens, connection then disconnection. i have even tried disabling my WiFi adapter.
One thing that has been suggested is that i need to set up some sort of internet sharing where i cann connect to the internet via wifi and gprs simultaneously but i cant seem to figure out how to do this.
Please help with either explaining how i could go about fixing the exception, OR, how i should go about fixing the dropped connection in …
hi guys,
i had a word with one of my friends and we found a way of resetting the values through the use of a for loop;
printf("%d floats merge sorted in %ld moves using %ld comparisons\n"
,i,moves(0),compares(0));
if(dupe(i,a))
printf("Duplicate keys found\n");
else
printf("All keys unique\n");
getch();
compares(-1);
moves(-1);
that would reset the values to -1 and then in the function i added this for statement;
long moves(int mode){
// adds to i in counting mode (>0), returns i
static int i=0;
if(mode>0)
i+=mode;
else if (mode==0)
return i;
//i+=mode;
else if (mode<0)
i=0;
}
i will try that later on tonight and will report back to you both tomorrow. thank you so very much for your time and effort with me. rep will be given!
Ooh, ok - understandings!
I get what you're saying about static holding the value. But in the program I sent you, why are there issues when i remove the static?
i think i've tried that too, like zeroing them at the menu but to no avail!
Thanks, I do appreciate your help. I am a beginner at this so let me try and explain what i thought was going on.
In the 'printf' statement you highlighted, i thought this was just bringing up the value of 'moves'. I don't quite understand what the 0 is doing.
In the second highlighted piece of code with the 'moves(2)', I thought this was where the calculation of the function is taking place. For example, all of the sorting is being done and then it is somehow calculated into how many moves have taken place.
And the obviously the function I initially showed you was the calculation I speak of.
But now you've showed me that I am wrong - very appreciative - but it leaves me more confused.
I understand that if 'moves(0)' has the 0, it will not enter the for loop of the function (Is that correct?) and so will just display 0. but what I don't understand is why if the static is typed in, a value does appear.
Hmm... I think I need to start again or something. Its just frustrating that all I want to do is reset this value that is being displayed - the next time it is called.
Here's the program so you can see what's going on. I have removed the static in the 'moves' function so you can see it just gives me a value of 0, but the 'compares' function works in the same way and WITH the static, it gives the correct value;
Oh and sorry for my spelling and punctuation, I hope this post is better.
//* Basic Sort Function Program *//
// Date: 18th March 2010
// Version: 1.1
// ----------------------------------------------------------------------------
// include directory libraries -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define N 5000
//-----------------------------------------------------------------------------
// declare functions -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int random (void); // creates random numbers
void sort(float *a,int low,int high);
/* parameters: starting address of array and low and high indexes */
void merge(float *low1,float *high1, float *high2);
/* parameters: pointers to low and high elements of half 1
calculates low element of half 2 as high1+1 and gets high
element of half 2 directly */
long moves(int mode);
long compares(int mode);
int dupe(int i,float *a);
void mergesort (void); // does merge sort
char menu(void); //displays main menu and returns option selected
//-----------------------------------------------------------------------------
// Main function -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int main(void){
int i, j; // number of records in database table
int finish=0; // 0 means continue loop. 1 means quit
char option='z'; // menu option
do{ // Do while loop to keep the menu always coming up after functions
option=menu();
switch(option){
case 'r': case 'R':{ // when 'r' pressed
random(); // the display …
thanks for your reply
i have tried that because thats what i thought too but when i do that, i just get a value of 0 returned to me
hi,
i have some code which is taking a value of how many moves a function is making to an array of numbers, and displaying it but basically, when i call the function initially, it will give the correct number of moves, when i call it again its adding the value to the previously displayed number unless i close the whole program down and start again. how do i reset the value each time i call the function.
i know its a very easy question for someone with a brain but i am still building mine and would really appreciate the help.
thanks
this is the code which is troubling me
long moves(int mode){
// adds to i in counting mode (>0), returns i
static int i=0;
if(mode)
i+=mode;
return i;
}
FILE *in;
in=fopen("file.txt","r");
int i=0;
while(fgets(buff,BUFSIZ,in)!=NULL){
a[i]=atof(buff);
i++;
}
//do something with the stuff you've read in
fclose(in);
i'm very much a beginner too but i THINK this will get you on the lines of reading in float values. its not difficult to convert it into reading characters from the file. try googling for parts of code - don't expect to just go out and find what your looking for. you have to play around yourself too otherwise its no fun.
sorry guys, just realised i wasn't including the stdlib.h library while using atof!!!
hi,
i have a very simple problem with my program and just need a push in the right direction and will be much appreciative of your help.
i have a bucket sort program which works fine. well i say fine, its fine when it is sorting the numbers initialised at the start of the program but when i want it to read in a file of numbers, its not playing ball. i can't see what the problem is. i'm using dev c++.
here is my full code;
/*Bucket sort */
#include<stdio.h>
#include<conio.h>
#define N 5000
/*Defining the strcuture for each node in the list*/
typedef struct node
{
float value;
struct node *link;
} node;
int main(void)
{
/*An array of structures,pointers to the structure*/
node counter[10], *n2,*n1;
char buff[BUFSIZ];
//float a[N];
FILE *in;
in=fopen("rand.txt","r");
float a[10] = {0.79,20.13,10.16,0.64,0.64,0.20,0.89,0.53,0.71,0.42};
float fa[10],temp;
int j,k=0;
float n,x;
system("cls");
/*Initializing the elements of the counter arrray to zero*/
int i=0;
// while(fgets(buff,BUFSIZ,in)!=NULL){
// a[i]=atof(buff);
// i++;
//}
for(i=0;i<10;i++)
{
counter[i].value = 0;
counter[i].link = 0;
}
/*Redcuing the value equal to index of an array*/
for(i=0;i<10;i++)
{
//n = a[i];
//j = n * 100;
//j = j/10;
/*Moving the values in to the appropriate bucket*/
/*If there are no elements in the bucket*/
if(counter[j] . value ==0 && counter[j] . link == 0)
counter[j] . value = a[i];
else
{
/*If there is only one element at that index*/
if(counter[j].link==0 && counter[j] .value != 0)
{
counter[j].link=(node *) …
i'm using Dev C++
i tried doing what you said and it makes no difference to the output.
hi guys,
i'm frustrated at my piece of code for a heap sort function. i believe everything is correct but i am a hardcore beginner at c. i have made a rand.txt file with some floats in it in the form;
91.175598
68.562500
96.664803
29.593500
43.156502
34.241001
59.178200
85.542702
81.852798
23.628799
but when i run it, its not reading them numbers and is just writing out 5000 (max array size) values of 0.0000. any ideas what i am doing wrong?
thanks
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXHEAP 100
#define N 5000
typedef char DATA ;
typedef struct heap {
float a[N];
int size;
} HEAP;
float gettop(HEAP *h); /* returns and removes top element from heap */
void insert(HEAP *h, float d); /* inserts d into heap */
int left(HEAP *h,int i); /* computes and returns i's left child index */
int right(HEAP *h,int i); /* computes and returns i's right child index */
int parent(HEAP *h,int i); /* computes and returns i's parent index */
int cmp(float a,float b); /* compares a and b,
returns -1 if(a<b),
returns 0 if(a == b) or
return +1 if(a>b) */
int main(void){
HEAP h;
int i,j;
char buff[BUFSIZ];
float a[N];
FILE *in;
in=fopen("rand.txt","r");
h.size=0; /* empty heap */
for(i=0;i<BUFSIZ;i++){ /* assemble heap */
if(a[i]!=' '){ /* ignore spaces */
insert(&h,(float)a[i]);
printf("%f",a[i]);
}
}
printf("\ncreated heap\n");
/* print heap out */
for(j=0;j<=i;j++){
if(j%20==0){
while(h.size)
printf("%f\n",(float)gettop(&h));
}}
getch(); …
not yet, once my programs done maybe... whenever that'll be!
haha, ok fair play. i think i'm getting a little bit excited about my first thread on here. sorry.
thanks for your help so far anyway. if there was any way i could give you more rep than i can, i would, but unfortunately i can't :(
i'm so sorry to you both! DURH, i just read through the code and forgot to change one line!
can you please both help me one one more thing.
basically you can see how it says that there are so many moves and so many comparisons. well basically, each time that line is coming up, instead of showing how many comparisons there were, it seems to be adding the comparisons to any comparisons which were done in a previous test.
how would i change the code so that everytime the test is done, it resets the value before it prints out the comparisons?
thanks, the original issue i had is now sorted. but now that i have changed the sort code as you've advised, the list is not being sorted - nor is it telling me how many comparisons are done on the firt time i do the bubble sort.
i have changed my bubblesort code to what you have advised - but now the numbers are not being sorted. if you look at the output now, the numbers are jumbled up as if random.
and also, on the first run of bubble sort, it says there are 0 comparisons and 0 moves while on second run, it gives values.
the second error is fixed now though thanks.
the i+1 is just so that the counting of the array prints out to start at 1. i don't think that has anything to do with the numbers in the array... or am i wrong?
and i have no idea if the comparisons are correct or not. thats something that one of my friends had helped me with. it seems to sort the numbers correctly. its just the issue of it adding a gap when it prints out the sorted list in bubble sort
ok i have done that but i am now still gettin issues when i use bubblesort. when i've made my 10 random numbers, merge sort will sort them 10 numbers fine in the same session or even when the program is closed and reopened whereas bubble sort is for some reason adding a value or adding a blank to the array so that there are 11 numbers being sorted if that makes sense
sorry guys, thanks so much for taking a look at this.
like i said i'm really a newby to this and i don't know what some of the code is doing its just guess work really like that int i bit you commented on. i've inserted my code below and i know its a total mess and that my read in code needs to be put into another function but i've forgotten how to do that too!!
if someone could help on the original problem outlined i would appreciate it very much.
thanks
//* Basic Sort Function Program *//
// Date: 18th March 2010
// Version: 1.1
// ----------------------------------------------------------------------------
// include directory libraries -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define N 5000
//-----------------------------------------------------------------------------
// declare maximum values -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
//-----------------------------------------------------------------------------
// declare functions -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int random (int i); // creates random numbers
void sort(float *a,int low,int high);
/* parameters: starting address of array and low and high indexes */
void merge(float *low1,float *high1, float *high2);
/* parameters: pointers to low and high elements of half 1
calculates low element of half 2 as high1+1 and gets high
element of half 2 directly */
long moves(int mode);
long compares(int mode);
int dupe(int i,float *a);
void bubblesort ( int i);
void merge(int i); // does merge sort
char menu(void); //displays main menu and returns option selected
//-----------------------------------------------------------------------------
// Main function -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
int main(void){
int i, j; // number of records in database …
/************bubble sort******************************************************/
void bubblesort ( int i){
int x,y,j;
float temp;
char buff[BUFSIZ];
float a[N];
FILE *in;
in=fopen("rand.txt","r");
i=0;
while(fgets(buff,BUFSIZ,in)!=NULL){
a[i]=atof(buff);
i++;
}
for(x = 0; x < i; x++)
for(y = 0; y < i; y++){
compares(1); //1 comparsion made
if(a[y] > a[y+1]){
temp = a[y+1];
a[y+1] = a[y];
a[y] = temp;
moves(2);
}// end of if
}//end of for
printf("%d floats merge sorted in %ld moves using %ld comparisons\n"
,i+1,moves(0),compares(0));
if(dupe(i,a))
printf("Duplicate keys found\n");
else
printf("All keys unique\n");
getch();
/* now output sorted data in a paged listing */
for(j=0;j<=i;j++){
if(j%20==0){
printf("press a key to continue\n");
getch();
system("cls");
}
printf("number %d is %lf\n",j+1,a[j]);
}
getch();
}//end of bubble sort
hi guys, this is my first post to the forum although i do use this website regularly for help. now i have a problem with my code for a sorting program i am making.
basically the program is used to make a random number list and then you should be able to sort the list using bubble sort, merge sort, heap sort and a tree based sort (i have no idea how to implement the last two of these)
i am a beginner at c and my code might be a mess but any help would be greatly appreciated.
a problem i am having is -
when i open the program and create the random numbers and then do a bubble sort, all is well and everything gets sorted properly. but then when i close the program and re open it and then do a bubble sort on the same set of numbers, for some reason, the sorted list has a new entry of 0.000... at position 1
its as if i have to insert a -1 somewhere so that it deletes this first value but i don't know where, and also why this problem only occurs when i re open the program.
(there is no problem when merge sort tries to do this by the way)
i will insert the code in the next post.
thanks