nadiam 0 Posting Pro in Training

Hello, so I'm trying to create an augmented reality web based app following this tutorial : Augmented Reality in 10 Lines of HTML

Im using xampp. The page is there but when I use the hiro image target nothing appears. My code is the same except that i changed the source according to my root folder.

demoAR.PNG

Anyone have this problem?

nadiam 0 Posting Pro in Training

Hello. I found this packet sniffer code that uses the pycap wrapper. Initially, its for live capture but I've changed it to read a .pcap file instead and im trying to understand it but some parts of it i can't i comprehend. could someone explain them to me please?

the full code is:

import socket
from struct import pack, unpack
import pcapy
import sys

def main(argv):
    dev = input("Enter file name to sniff : ")

    print("Sniffing file " + dev)

    # Read offline
    cap = pcapy.open_offline(dev)

    #start sniffing packets
    while(1) :
        (header, packet) = cap.next()
        parse_packet(packet)

# change to string format 00:00:00:00:00:00
def eth_addr (a) :
    b = "%.2s:%.2s:%.2s:%.2s:%.2s:%.2s" % (str(a[0]) , str(a[1]) , str(a[2]), str(a[3]), str(a[4]) , str(a[5]))
    return b

def parse_packet(packet) :

    # Ethernet header
    eth_length = 14

    eth_header = packet[:eth_length]
    eth = unpack('!6s6sH' , eth_header)
    eth_protocol = socket.ntohs(eth[2])
    with open("file.txt", "a") as file1:
        file1.write("Ethernet Header : \n")
        file1.write("Destination MAC : " + str(eth_addr(packet[0:6])) + "\n" + "Source MAC : " + str(eth_addr(packet[6:12])) + "\n" + "Protocol : " + str(eth_protocol) + "\n\n")

    #Parse IP packets, IP Protocol number = 8
    if eth_protocol == 8 :
        #Parse IP header
        #take first 20 characters for the ip header
        ip_header = packet[eth_length:20+eth_length]

        #now unpack 
        iph = unpack('!BBHHHBBH4s4s' , ip_header)

        version_ihl = iph[0]
        version = version_ihl >> 4
        ihl = version_ihl & 0xF

        iph_length = ihl * 4

        ttl = iph[5]
        protocol = iph[6]
        s_addr = socket.inet_ntoa(iph[8]);
        d_addr = socket.inet_ntoa(iph[9]);

        with open("file.txt", "a") as file2:
            file2.write("IP Header : \n")
            file2.write("Version : …
nadiam 0 Posting Pro in Training

update : using re.finditer gives me an error : unhashable type bytearray. so this is my current code im using :

BLOCKSIZE = 65536
bytes1 = bytearray(base64.b16decode(self.txt_mac))
with open(self.txt_filename, "rb") as binaryfile :
   while True:
       readfile = bytearray(binaryfile.read(BLOCKSIZE))
       if len(readfile):
          index = 0
          while index < len(readfile):
              index = readfile.find(bytes1, index)
              if index != -1:
                with open("LogFile.txt", "a") as found:
                    found.write("Found bytes1 at : " + str(index) + "\n")
                    index += 6 # +6 because len(bytes1) == 6

               else:
                   break
        else:
            break

However, instead of using "a", accumulate all the text and only write "w" to the file once.

nadiam 0 Posting Pro in Training

Hi. im trying to append a text file that is created by another class via another class which are threads.

for example, i have :

class AClass(QThread):
    def run(self):
        with open("Log.txt", "w") as h:
            h.write("Blabla \n")

class BClass(QThread):
    def run(self):
        with open("Log.txt", "a") as t:
            t.write("new line of txt \n")

However, when BClass doesn't append the new line. but if its a new file say "LogF.txt" it will append to that new file. I tried using a+ too but no go. im assuming because they are running at the same time or smtg like that so BClass can't append to Log.txt because to BClass that file doesn't exist? How would i get around that? theres a function, isAlive() but i think my googling skills are weak coz i can't find any sort of documentation about it, so im not sure how to use it or if it will resolve my issue. Any help is greatly appreaciated.

nadiam 0 Posting Pro in Training

i just wanted to update my code here as it has changed.

with open(filename, "rb") as binaryfile:
    while True:
        read_file = binaryfile.read()
        if len(read_file):
            for find_bytes in re.finditer(bytes1, read_file):
                with open("foundhex.txt", "a") as found1:
                    found1.write("Found bytes at : " + str(find_bytes.start()) + " " +str(find_bytes.end()) + "\n")
        else:
            break

this code finds all occurences of bytes1. I am still trying to figure out how to find the 6 bytes before bytes1. there was an idea to use slice but im not sure how to use it with the code i have now (for loop). i was thinking something like:

find_prevbytes = read_file[find_bytes -6:6]

but ofc theres the TypeError.

nadiam 0 Posting Pro in Training

thank you for your reply woooee. ive ended up with this code, using re.finditer

import re

with open(filename, "rb") as binaryfile:
    while True:
        read_file = binaryfile.read()
        if len(read_file):
            for find_bytes in re.finditer(bytes1, read_file):
                with open("foundhex.txt", "a") as found1:
                    found1.write("Found bytes at : " + str(find_bytes.start()) + " " +str(find_bytes.end()) + "\n")
        else:
            break

it finds all occurences of bytes1

nadiam 0 Posting Pro in Training

Hi, i wasn't sure about the title of my question, hope its okay. Anyway, the program i have is suppose to read a binary file then find for specific bytes like this:

bytes1 = bytearray(b'\x41\x64\x6F\x62\x65\x20')
filename = "portrait1.dng"
with open(filename, "rb") as binaryfile:
    with open("foundhex.txt", "w") as found:
        found.write("File that is analysed : " + filename + "\n")
        found.write("Date of analysis : " + str(today) + "\n")
    while True:
        read_file = bytearray(binaryfile.read(1024))
        find_bytes1 = read_file.find(bytes1, 0)
        if fine_bytes1 != -1:
            with open("foundhex.txt", "a") as found1:
                found1.write("Found 41646F626520 at : " + str(find_bytes1) + "\n")
        if not read_file:
            break

basically, it finds the bytes then writes the positions. i checked the file that is being read using a hex editor and the bytes (bytes1) that i am looking for has 12 occurences but only 9 occurences of it are "found". so now im confused. is my program not reading the entire file, thats why only 9 found? or is there something wrong with my code? as of right now im only using a 16.2mb file but later on ill be using a 8gb file. is there a difference for file sizes when reading in chunks? because i ended up changing the "size" to random numbers and found that read(901) found 11 occurences, not only 9. haven't hit 12 yet though. Please, could someone explain this to me. thank you in advance.

nadiam 0 Posting Pro in Training

Hi. Sorry if the question is confusing or weird but I am trying to find a specific number of bytes after finding a different set of bytes. Hopefully with code and my explaination of code, i'll get my question across.

import base64

find_bytes = bytearray(base64.b16decode('46726F4B6E6F'))
with open("readfile.raw", "rb") as f:
    file_bytes = bytearray(f.read())
    found_pos = file_bytes.find(find_bytes, 0)
    with open("foundhex.txt", "w") as found:
        found.write("Found 46726F4B6E6F at : " + str(found_pos))

Okay so. I have a set of bytes i want to find find_bytes : 46726F4B6E6F, then with those bytes found i want to find the previous 6 bytes before them. In a RL situation, i wouldn't know what those 6 bytes are, I only know that they are 6 bytes and that they are positioned before find_bytes. I am unsure how to achieve this. i was thinking use range() but im not sure how to use it with bytearray or if it is even the correct method.

I hope i explained it properly. please let me know if u need any more clarification.

nadiam 0 Posting Pro in Training

Okay. I just found bytearray() which has accomplished my goals by:

with open("portrait1.dng", "rb") as binaryfile :
    myArr = bytearray(binaryfile.read())

with open("readfile.raw", "wb") as newFile:
    newFile.write(myArr)

but my questions still sort of stand because as i mentioned the current file i am testing is only 16.2mb and the real file which will be used is 8gb and i tested this code with that huge file and my laptop froze. so a couple of updated questions/thoughts:

  1. read and write obviously works but which operation uses most RAM? as one of it should be the reason why my laptop froze. is there a way to lessen that load? coz i can't keep testing and having my laptop freeze, that is surely unhealthy for it. my whole university life is on this (translation, if it dies i die).

  2. is there a better way to read the file? like portion by portion perhaps? how is that achieved? because i dont really need the write, the write is just for me to see that the file is wholly read. i need the read for other processes.
nadiam 0 Posting Pro in Training

hi. i have a really basic question (really new to python). how do i read an entire binary file? from https://www.devdungeon.com/content/working-binary-data-python , data = binary_file.read() is to read the whole file at once. so i have a .dng file to test, which is 16.2mb, and i did:

with open("portrait1.dng", "rb") as binary_file:
        #Read the whole file at once
        data = binary_file.read()
        #Return the hexadecimal representation of the binary data, byte instance
        hexa = binascii.hexlify(data)
        with open("readprotrait1.raw", "wb") as write_file:
              write_file.write(hexa)

im using a hex editor to see if the data from .dng gets copied to the .raw file but only a portion of it gets copied. same result goes when i use a while loop like :

while True:
      data = binary_file.read()
      if not data:
           break
      #return hex rep and write

if i put a size(1024) in the .read(), only the last few lines of the data is written. so does it actually read the whole file and at the "write" part is where it gets complicated(doesn't write complete)? or am i missing something?

nadiam 0 Posting Pro in Training

I did this:

<input type="tel" name="phone" placeholder="+6012-3456789" pattern="^[+](6)(0)[1-9]\d{1}-[0-9]\d{6}$" title="+6012-3456789" required>

it works.. but is there a better way? or this is the way?

nadiam 0 Posting Pro in Training

okay so i removed the slashes and it worked. so i tried to put in the pattern that i actually wanted which is a pattern like +6012-3456789 but i only achieved 12-3456789. how do i make it so that +60 has to be entered and in that order +60.

what i have:

<input type="tel" name="phone" placeholder="+6012-3456789" pattern="^[1-9]\d{1}-[0-9]\d{6}$" title="+6012-3456789" required>

nadiam 0 Posting Pro in Training

Hello. I have a project to develop a tool that reads Windows 7 raw memory dump. My lecturer says that he'd rather we use python or c coz that's his specialy but we can choose whatever. We chose python (bcoz i feel like its an opportunity to further learn about python) but what do you guys think? what language would be a good choice? then theres the whole GUI thing to think about, if we use python we gotta find a GUI framework etc...

Anyway, so this tool is suppose to get the network packet from a memory dump file and then analyse it to get some data. We're having trouble just trying to figure out where to start looking. i mean obviously reading through the pcap is one place to start but then what else? what else do we need to start chugging this train along? to actually start development.

My lecturer has given us all the functional requirements, things the tool should be able to do like calculating hash, detect ip packet, get info from ip packet, etc. but to actually start coding, what else should we look into besides pcap?

Any direction/help/insturctions, we are forever thankful for.

nadiam 0 Posting Pro in Training

Hello, i know this question has been asked a million times but I just cant seem to get it right. I googled and found this and tried to use the pattern given but still the pop up still shows. I don't know what im doing wrong but its getting frustrating as obviously it worked for the person but not for me unfortunately.

<input type="tel" name="phone" placeholder="+60##-#######" pattern="/^(7|8|9)\d{9}$/" title="7878787878" required>

as you can see what i wanted is a pattern for +60##-####### but couldn't figure it out so as i said i tested with the one from the link but when i enter 7878787878 the pop up still says, "please follow requested format" although this pattern worked for the person.

i tried my own pattern /^(+60)\d{2}\(-)\d{7}$/, entered an invalid pattern and no pop up came out. please help me. and thank you in advance.

nadiam 0 Posting Pro in Training

Ohh.. OKay. Thank you so much. So i did this:

import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.IOException; 
import java.io.FileWriter;

class TestFile2{
    public static void main(String[] args) {
        try { 
            PrintWriter out = new PrintWriter(new FileWriter("output"));
            File f1 = new File("c://Java/Lab 1/MyDocument/Data.txt");
            File d1 = new File("MyDocument");

            if(f1.isDirectory()){
                String s = f1.getName() + " is a directory";
                out.print(s);
            }else if(f1.isFile()){
                String s = f1.getName() + " is a file";
                out.print(s);
            }

            if(d1.isDirectory()){
                String s = d1.getName() + " a directory";
                out.print(s);
            }

            if (f1.exists()){
                FileReader in = new FileReader(f1);//object FileReader that refers to f1
                int data = in.read(); //read a char at a time
                while (data != -1) {
                    out.write(data);
                    data = in.read();
                }
                out.print(data);
                System.out.flush();
                out.close();
            }

        } catch (Exception e) {
            System.out.println("Exception: "+e);
        }
    }
}
nadiam 0 Posting Pro in Training

Oh.. hmm how come we've been asked to use print() method? unless we're suppose to figure the whole no such thing as print() method?

iv. Use method print() to write the characters read (the file content) to file “output”.

nadiam 0 Posting Pro in Training

Okay, update. i didnt have out.close() so it couldnt add what i wanted to the file. but how do i use method print() ?

nadiam 0 Posting Pro in Training

Hello, so I have this program which should be creating a file called output and appending some content from another file,data.txt, accordingly. Creating file called output works but then the output file is empty. what am i doing wrong?

Oh and Im suppose to use method print() but that gives me a bunch of errors that says its not applicable.

import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.io.IOException; 
import java.io.FileWriter;

class TestFile2{
    public static void main(String[] args) {
        try { 
            PrintWriter out = new PrintWriter(new FileWriter("output", true));
            File f1 = new File("c://Java/Lab 1/MyDocument/data.txt");
            File f2 = new File("MyDocument", "data.txt");
            File d1 = new File("MyDocument");

            if(f1.isDirectory()){
                out.print(f1.getName() + " is a directory");
            }else if(f1.isFile()){
                out.print(f1.getName() + " is a file");
            }

            if(d1.isDirectory())
                out.print(d1.getName() + " a directory");

            if (f1.exists()){
                FileReader in = new FileReader(f1);//object FileReader that refers to f1
                int data = in.read(); //read a char at a time
                while (data != -1) {
                    out.write(data);
                    data = in.read();
                }
                out.print();
                System.out.flush();
                in.close();
            }

        } catch (Exception e) {
            System.out.println("Exception: "+e);
        }
    }
}
nadiam 0 Posting Pro in Training

Hi, I'm really, really new to Haskell. I'm practicing with simple online questions and there's a hcf question which I found the answer to online(http://snipplr.com/view.php?codeview&id=11973) but I still don't understand the coding. I'm not sure if this kind of question is accepted in Daniweb but yeah. Could someone please explain to me?

hcf a 0 = a
hcf a b = hcf b y
    where y = mod a b

mod a b, ofc understandable but the first 2 lines. why is there a 0, why = a ?

nadiam 0 Posting Pro in Training

Hello. I have this tutorial and I'm at a lost. The program is suppose to calculate the call charges according to the rates. conditions:

a) all calls start at 600pm and before 700am will be given 50% discount from the normal rate
b) any calls that starts at 700am and before 600pm will be charged the normal rate
c) the normal charge is 0.30 per minute

so far i got the conditions right but lets say if call time starts at 1745 and duration is 30 minutes which means call ends at 1815, there's that 15 minuts of normal rate and 15 minute of 50% discount which total charge would be 6.75. That's the part I'm stuck on.

code:

/*
ALGORITHM
READ INPUT VALUE CALL TIME
READ INPUT VALUE DURATION
CALCULATE CALL CHARGE
DISPLAY CALL CHARGE
*/

#include<stdio.h>

typedef struct {
    int time; 
    int duration;
    float charge;
}telephonecharge;

void calculateCharge(int, telephonecharge [20]);

int main() {
    int i, numCalls, First, Last;
    telephonecharge input[20];

    printf("Insert number of calls : \r\n");
    scanf_s("%d", &numCalls);

    for (i = 0; i < numCalls; i++) {
        printf("\r\nInsert Call Time and Call Duration : \r\n");
        scanf_s("%d %d", &input[i].time, &input[i].duration);   
    }

    calculateCharge(numCalls, input);

    for (i = 0; i < numCalls; i++) {
        printf("Call Time : %d,  Duration : %d, Charge : RM %.2f \r\n", input[i].time, input[i].duration, input[i].charge);
    }

    return 0;
}

void calculateCharge(int N, telephonecharge data[20]) { //N = numCalls
    int i;
    float c;

    for (i = 0; i < N; i++) {
        if (data[i].time > …
nadiam 0 Posting Pro in Training

Thank you! will keep your advice in mind.

nadiam 0 Posting Pro in Training

Hello. I have an exercisse to convert from 24-hour to 12-hour clock. code:

/*ALGORITHM
READ INPUT VALUE IN 24-HOUR FORMAT
DISPLAY THE EQUIVALENT 12-HOUR CLOCK WITH THE PERIODS AM OR PM
*/

#include<stdio.h>
#include<conio.h>

int InputValid24Hour(void);
void Output12HourClock(int);

void main() {
    int data;

    data = InputValid24Hour();
    Output12HourClock(data);
    _getch();
}

int InputValid24Hour(void) {
    int input24hour;
    int First2Digit, Last2Digit;

    printf("Enter time in 24-hour format: \r\n"); //ask for input

    do {
        scanf_s("%d", &input24hour); //read input

        First2Digit = input24hour / 100; //get first 2 digits
        Last2Digit = input24hour % 100; //get last 2 digits

        if ((First2Digit < 0) || (First2Digit > 24) || (Last2Digit >= 60))
            printf("\r\nInvalid 24-hour clock..");

    } while ((First2Digit < 0) || (First2Digit > 24) || (Last2Digit >= 60));

    return(input24hour);
}

void Output12HourClock(int i) { //int i value from InputValid24Hour() see main()
    int First, Last;

    First = i / 100;
    Last = i % 100;

    if (First > 12) {
        First = First - 12;
        printf("%02d = %02d:%02d pm\r\n", i, First, Last);
    }
    else if (First == 00) {
        First = 12;
        printf("%02d = %02d:%02d am\r\n", i, First, Last);
    }
    else {
        printf("%02d = %02d:%02d am\r\n", i, First, Last);
    }

}

Output : http://imgur.com/a/OtfJL

the problem'ss at 24, it doessn't sshow 00 when it sshould sso it sshould be 0024 = 12:24 am; how do i get 00 to be displayed?

thankss

nadiam 0 Posting Pro in Training

Hello. I'm taking subject compiler construction. and there is a question and the answer that i don't anderstand.

if it was digit -> [0 - 9] then it would be ->0->1->2->3->4->5->6->7->8->9 final state

digits -> digit+ then it would be ->digit->digit->digit loop final state

but this question i dont understand the solution:
write a transition diagram for scientific number

number → digits (. digits)?(E[+-]? digits)?

the answer:

http://imgur.com/a/98551

my question:

why is there a loop before the period? The dot . between 13 and 14, does the period mean something?

why is there a loop at 15? is it because of the question mark? question mark means zero or one

then after the +- I am so lost. as well as the "other" 's and keene star on the "other" 's

why is it looped at 18 not 17 ?

i'm also lost on the bottom arrows. 13 -> 16, 16 -> 18

Sorry for the questions and if the questions really stupid. my lecturer is like a f1 car in class.

nadiam 0 Posting Pro in Training

Hi. I wasn't sure which topic this falls under as it sort of concerns both OS and this is, I'm sure, a really noob (I want to start learning linux) question but can i use one pen drive between the 2 different OS's?

Earlier I was using my pen drive which is a SanDisk Cruzer Pop 4GB between my Windows 8.1 laptop and my recently installed Ubuntu 14.04 laptop and it was going well. On both laptops I safely removed the pen drive before unplugging it but now the pen drive can't be detected. I've tried it on both laptops and 2 other PCs and its undetected.

If i was suppose to format it somehow to make it compatible to both OS's, well I didn't know so I didn't do so. So basically I just want to know if its broken, is there a way to fix it if it is broken and maybe a kind soul could point me into the right direction so this doesn't happen to my other pen drives (formatting for compatibility perhaps).

Sorry if this seems like a really stupid question. Anyway, thanks in advance!

nadiam 0 Posting Pro in Training

I sorta just googled each Hardware ID and winged it( rproffitt, went your way). went to the manufacturers website and installed. got most of it fixed excpet for High Definition Audio Device.

device_manager.JPG

googled it but no luck. I have Realtek and NVIDIA, i thought itll end there. tried the Playing Audio troubleshoot, didnt fix it. Oh well, I'll just have to keep trying.

nadiam 0 Posting Pro in Training

so the Naza doesnt really need the distributed relationship and the other 2 attributes(black and 7 seater)? just need to show relevance to Kassim not the Naza?

nadiam 0 Posting Pro in Training

Hi. I have this Semantic Network exercise with no answer and i just want to check if i am correct. Please check this image: http://imgur.com/a/iC0dW

The exercise:

Kassim is a 45 year old man who has 2 wives and 7 kids. He workds as a surgeon in a private hospital and owns a Naza Ria. Naza Ria is distributed by the Naza Mototrs. This car has a capacity of 7 seater and is black in colour. Naza Mototrs also distributes Brabus, Peugot, Ferrari, Maserati, and a few more.

*You'll notice at the Naza Mototrs relationship I only did Brabus and Peugot (purposely), but i get the idea of the relationship.

So question:

  1. For wives and children do i place the numbers inside the oval as well? So instead of wives, children its 2 wives, 7 children. Or is there another branch of relationship next to those objects so itll be HAS Two, HAS Seven. ?

  2. In the object, can I list multiple or just one by one? like for the "Naza motors also distributes...." do i have a relationship for each brand or can i put them in a single bubble?

Thanks in advance!

nadiam 0 Posting Pro in Training

Hi. i ran a SFC /SCANNOW on my laptop(Asus, Windows 8.1) and there are corrupt files according to cmd. Checked the CBS log file and found multiple DIRSD OWNER WARNING , Ignoring duplicate ownership for directory AND [SR] Cannot repair member file [l:36{18}] . Could someone explain to me what the first one means? I mean if its possible to fix all three problems, how? I guess, if you see the whole log then only you'd know how to help but theres like dozens of lines (crazy to copy paste all that). So how do i proceed? maybe i'll attach it? is that safe? is the log safe to share to public?

nadiam 0 Posting Pro in Training

NVM

nadiam 0 Posting Pro in Training

Shark_1, im trying to get all rows but with a specific value in a column. like for example:

ID | FLD_ORDER_ID | FLD_PRODUCT_ID | FLD_QTY | FLD_SUBTOTAL
1 | A123
2 | A548
3 | A123
4 | A487
5 | A548
for example i want to get the rows with fld_order_id AS A123 and display those rows only. both queries dont get what i want.

and i fixed the original problem by selecting all fields. and i forgot to add my 'run_sql_query' before brackets"select...."

nadiam 0 Posting Pro in Training

Hi, i have a datagridview : grd_ol and i added a button to it:

Dim btnColumn As New DataGridViewButtonColumn()
btnColumn.HeaderText = "Invoice"
btnColumn.Text = "View Invoice"
btnColumn.UseColumnTextForButtonValue = True
grd_ol.Columns.Add(btnColumn)

the table sort of looks like this:

| ORDER_ID | CUSTOMER_ID | STAFF_ID | ORDER_DATE | TOTAL(RM) | INVOICE |
| id1 | custid1 | staffid1 | 13/12/2016 | 12345 | 'View Invoice' |
| id2 | custid5 | staffid3 | 13/12/2016 | 178342 | 'View Invoice' |
| id3 | custid9 | staffid2 | 13/12/2016 | 1543 | 'View Invoice' |

how do i get the order_id of the row by buttonClick of 'view invoice'? is it on grd_ol_CellContentClick?

i thought something like this would work but theres like a blue line and says End of statement expected
grd_ol.Rows[DataGridView.SelectedRows[0].Index].Cells[0].Value.ToString()

nadiam 0 Posting Pro in Training

Hi.

im trying to get data from table TBL_ORDERITEM

FLD_ORDERITEM_ID | FLD_ORDER_ID | FLD_PRODUCT_ID | FLD_QTY | FLD_SUBTOTAL

grd_productlist.DataSource = ("SELECT FLD_ORDER_ID,FLD_PRODUCT_ID,FLD_QTY,FLD_SUBTOTAL FROM TBL_ORDERITEM_A15428 WHERE FLD_ORDER_ID = '" & id & "' IN (SELECT '" & id & "' FROM TBL_ORDERITEM_A15428 GROUP BY '" & id & "' HAVING COUNT(*) > 1 )")

grd_productlist.Columns(2).HeaderText = "Product ID"
grd_productlist.Columns(3).HeaderText = "Quantity"
grd_productlist.Columns(4).HeaderText = "Subtotal"

but I get Index out of range error poiting at -> grd_productlist.Columns(2).HeaderText = "Product ID"

why?

nadiam 0 Posting Pro in Training

Adding And Updating A Calculated Column To DGV

This helped me; for future reference.

nadiam 0 Posting Pro in Training

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code so its public

Dim dt As New DataTable

in private sub form load

grd_order.DataSource = dt

in private sub for product list

Private Sub product_list(ByVal pid As String)
    Dim getproduct As String = "SELECT FLD_PRODUCT_ID,FLD_PRICE FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
    Dim reader As New OleDb.OleDbDataAdapter(getproduct, myconnection)
    Dim getcolumns As String = "SELECT FLD_QTY,FLD_SUBTOTAL FROM TBL_ORDERITEM_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
    Dim reader2 As New OleDb.OleDbDataAdapter(getcolumns, myconnection)
    reader.Fill(dt)
    reader2.Fill(dt)
End Sub

http://imgur.com/a/TKu0K

Now i want to know how to calculate the subtotal? because user can key in the quantity of the product they want. like in the picture : CK005 | 850 | , quantity and subtotal cells are empty. how would i get the value from cell Price and cell Quantity? to calculate the subtotal : Subtotal = valueFromQtyCell * valueFromPriceCell and put it into cell Subtotal for each its own row. Then get each value from column subtotal of each row and add them up as the Total Price; TotalPrice = valueFromSubtotalCellOfEachRow this im assuming needs a loop?

nadiam 0 Posting Pro in Training

Thank you, tinstaafl! Okay will open a new topic for my other question.

nadiam 0 Posting Pro in Training

code for the listbox - datagridview interaction

At the top of the code so its public

Dim dt As New DataTable

in private sub form load

grd_order.DataSource = dt

in private sub for product list

Private Sub product_list(ByVal pid As String)
    Dim getproduct As String = "SELECT FLD_PRODUCT_ID,FLD_PRICE FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
    Dim reader As New OleDb.OleDbDataAdapter(getproduct, myconnection)
    Dim getcolumns As String = "SELECT FLD_QTY,FLD_SUBTOTAL FROM TBL_ORDERITEM_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
    Dim reader2 As New OleDb.OleDbDataAdapter(getcolumns, myconnection)
    reader.Fill(dt)
    reader2.Fill(dt)

End Sub

http://imgur.com/a/TKu0K

Thats my table after multiple product ids are selected from list box. i want to change the name of the Header Text. i thought of using this dt.Columns(0).HeaderText = "" but nope. its the databinding thing.

I was also wondering how to calculate the subtotal? because user can key in the quantity of the product they want. like in the picture : CK005 | 850 | , quantity and subtotal cells are empty. how would i get the value from cell Price and cell Quantity? to calculate the subtotal : valueFromQtyCell * valueFromPriceCell for each row.

nadiam 0 Posting Pro in Training

@tinstaafl thank you! So based on the select query, when a product id is selected from listbox, new row that is populated with data is added to the table.

how do i change the column name? coz dt follows the column name from database like FLD_PRODUCT_ID etc, want to change it to PRODUCT ID etc

nadiam 0 Posting Pro in Training

hmm i think i asked the wrong question. its not how to add the values because i can do that, its more of making each row and cell unique from each other. oh well. please if anyone can help. thank you.

nadiam 0 Posting Pro in Training

@ddanbe i did change it and i got IndexOutOfRangeException was handled error : There is no row at position 1.

nadiam 0 Posting Pro in Training

So is what im asking not possible to do? is there another way to accompolish what i want?

nadiam 0 Posting Pro in Training

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click
   grd_order.RowCount = grd_order.RowCount + 1
End Sub

everything to do with lst_product:

lst_product.DataSource = run_sql_query("SELECT * FROM TBL_PRODUCTS_A154287 ORDER BY FLD_PRODUCT_ID ASC")
lst_product.DisplayMember = "FLD_PRODUCT_ID"

**//This code snippet lets user click on a product id in the list and populates the id and its corresponding price into the column cell**

Private Sub product_list(ByVal pid As String)

   Dim getPID As String = "SELECT * FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"

   Dim thePTable As New DataTable

   Dim reader As New OleDb.OleDbDataAdapter(getPID, myconnection)

   reader.Fill(thePTable)

   For i As Integer = 0 To grd_order.RowCount - 1
       grd_order(0, i).Value = thePTable.Rows(0).Item("FLD_PRODUCT_ID")
       grd_order(1, i).Value = thePTable.Rows(0).Item("FLD_PRICE")
   Next
End Sub

The btn_addline does work and adds a new row(Row1) to the datagrid the problem is when another row(Row2) is added.

When new row(Row2) is added after btn_addline and a new product id is selected from lst_product the data in Row1 changes along with the selected id. so instead of Row1 : ID0001 | RM12, Row2 : ID0002 | RM45. I get Row1 : ID0002 | RM45, Row2 : ID0002 | RM45

How do i code so that each row/cell is unique?

nadiam 0 Posting Pro in Training

@Xavier_5 thanks! this helped.

nadiam 0 Posting Pro in Training

Hi. thank you @Reverend Jim that did help. how do i create a new row of textboxes everytime button is clicked? As for now when button is clicked 1 row of 3 textboxes is added. I want so every time button is clicked a new row is added.

I changed the Const ROWS and COLS

 Const ROWS = 1       
 Const COLS = 3 

And added this so textbox name is different

 Dim i As Integer
 i += 1
 newbox.Name = "txt_" & i

Later on users will fill in data into the textboxes to be inserted into database, which i will have to figure out how to do later.

nadiam 0 Posting Pro in Training

Hi. Im using vb 2010. I want to dynamically add textboxes to my form by clicking on a button. I've google searched and so far this code worked:

 Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click
        Dim txtB1 As New TextBox
        Dim i

        For i = 0 To 5
            Me.Controls.Add(txtB1)
            With txtB1
                .Name = "chkDemo" & i
            End With
        Next i
    End Sub

but it only creates one(well as i can see) and i cant tell whether the name is actually set as chkDemo(how to check?). I tried adding .Location = 20,20 but got error something to do with integer. Once i got this down, my goal is to actually dynamically add multiple textboxes or even maybe a combobox at the same time.

thanks in advance

nadiam 0 Posting Pro in Training

right. right. gosh. created a new function. thanks!

nadiam 0 Posting Pro in Training

run_sql_query() runs correctly as i used it to get the data into the datagrid.

i just realized it might be because of how i set up the form. user has to select a category from the combobox which is populated by refresh_grid() only then the table will be filled with the data. is this why "delete" does not work?

refresh_grid():

Private Sub refresh_grid(ByVal category As String)
        grd_list.DataSource = run_sql_query("SELECT FLD_PRODUCT_ID,FLD_PRODUCT_NAME,FLD_PRICE,FLD_BRAND,FLD_DESC,FLD_QTY FROM TBL_PRODUCTS_A154287 WHERE FLD_TYPE = '" & category & "'")

        grd_list.Columns(0).HeaderText = "Product ID"
        grd_list.Columns(1).HeaderText = "Product Name"
        grd_list.Columns(2).HeaderText = "Price"
        grd_list.Columns(3).HeaderText = "Brand"
        grd_list.Columns(4).HeaderText = "Description"
        grd_list.Columns(5).HeaderText = "Quantity"
    End Sub

combobox selected:

    Private Sub cmb_type_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_type.SelectedIndexChanged
        refresh_grid(cmb_type.Text)
    End Sub

fill the table:

 Private Sub frm_productlist_a154287_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmb_type.DataSource = run_sql_query("SELECT FLD_TYPE FROM TBL_PRODUCTS_A154287 GROUP BY FLD_TYPE")
        cmb_type.DisplayMember = "FLD_TYPE"

        refresh_grid(cmb_type.Text)
    End Sub
nadiam 0 Posting Pro in Training

Hi guys. Im trying to delete a row from a table in DataGridView (VB 2010) and my database (MS Access 2013) but on "Delete" it shows that it doesnt get the ID of that data row, so it wouldnt actually know what data to "Delete"

delete btn:

Private Sub btn_dlt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_dlt.Click
        Dim delete_confirmation = MsgBox("Are you sure you would like to delete the product '" & currentpid & "'?", MsgBoxStyle.YesNo)

        If delete_confirmation = MsgBoxResult.Yes Then

            run_sql_query("DELETE FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID = '" & currentpid & "'")

            Beep()
            MsgBox("The product '" & currentpid & "' has been successfully deleted.")

        End If
End Sub

initializing currentpid as public

 Dim currentpid As String

currentpid :

  Private Sub getProductID()
        Dim current_row As Integer = grd_list.CurrentRow.Index
        currentpid = grd_list(0, current_row).Value

        //TO TEST IF ID AND NAME IS READ
        txt_id.Text = currentpid 
        txt_pname.Text = grd_list(1, current_row).Value
    End Sub

    Private Sub grd_list_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grd_list.CellContentClick
        getProductID()
    End Sub
nadiam 0 Posting Pro in Training

Hi, im using vb2010 with MS Access 2013. I have this form that displays ID values from database into a listbox And when an ID is clicked the details that correspond with that ID are displyed into textboxes.

Screenshots :

Forms : http://imgur.com/a/NrTTD
Display details : http://imgur.com/a/twF7P

The delete button does delete the data from database but im having trouble with the form as when the data is deleted the "deleted" data is still displayed on the form. How do i refresh the forms so it does not display the deleted data after deletion?

Delete Button

Private Sub btn_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_delete.Click
        Dim delete_confirmation = MsgBox("Are you sure you would like to delete the product '" & txt_pname.Text & "' with ID '" & txt_pid.Text & "'?", MsgBoxStyle.YesNo)

        If delete_confirmation = MsgBoxResult.Yes Then

            Dim deleteproduct As String = "DELETE FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID = '" & txt_pid.Text & "'"
            Dim mywriter As New OleDb.OleDbCommand(deleteproduct, myconnection2)

            mywriter.Connection.Open()
            mywriter.ExecuteNonQuery()
            mywriter.Connection.Close()

            Beep()
            Dim msgbx As String = MsgBox("The product '" & txt_pname.Text & "' has been successfully deleted.")

        End If

            mywriter.Connection.Close()
        End If
    End Sub

Cat Button (Display Cat details)

Private Sub btn_cat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cat.Click
        Dim getProduct As String = "SELECT FLD_PRODUCT_ID,FLD_TYPE FROM TBL_PRODUCTS_A154287 WHERE FLD_TYPE = 'Cat'"

        Dim theTable As New DataTable

        Dim reader As New OleDb.OleDbDataAdapter(getProduct, myconnection)

        reader.Fill(theTable)

        lst_product.DataSource = theTable
        lst_product.DisplayMember = "FLD_PRODUCT_ID"

        refresh_text(lst_product.Text)
        btn_edit.Enabled = True
        btn_update.Enabled = True
        btn_delete.Enabled = True …
nadiam 0 Posting Pro in Training

Visual Basic 2010 and Microsoft Access 2013

I have a product table in MS with fields : fld_id,fld_name,fld_img,fld_price,fld_type

fld_img i set it as attachment and of course attached the corresponding image to it - is this wrong?

this is my code to get the data into the datagridview. my form uses combobox to select the type of product to display. right now the image column just displays the file name of image. how to display the image instead?

Public Class frm_pl

    Private Sub frm_pl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim getProducts As String = "SELECT FLD_TYPE FROM TBL_PRODUCTS_A154287 GROUP BY FLD_TYPE"
        Dim theTable As New DataTable
        Dim reader As New OleDb.OleDbDataAdapter(getProducts, myconnection)
        reader.Fill(theTable)
        grd_pl.DataSource = theTable

        cmb_type.DataSource = theTable
        cmb_type.DisplayMember = "FLD_TYPE"

        refresh_grid(cmb_type.Text)
    End Sub
    Private Sub refresh_grid(ByVal fld_type As String)
        Dim getProducts As String = "SELECT FLD_PRODUCT_ID,FLD_PRODUCT_NAME,FLD_IMG,FLD_PRICE FROM TBL_PRODUCTS_A154287 WHERE FLD_TYPE = '" & fld_type & "'"
        Dim theTable As New DataTable
        Dim reader As New OleDb.OleDbDataAdapter(getProducts, myconnection)
        reader.Fill(theTable)
        grd_pl.DataSource = theTable

        grd_pl.Columns(0).HeaderText = "Product ID"
        grd_pl.Columns(1).HeaderText = "Name"
        grd_pl.Columns(2).HeaderText = "Image"
        grd_pl.Columns(3).HeaderText = "Price (RM)"
    End Sub
    Private Sub btn_mm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_mm.Click
        frm_mainmenu.Show()
        Me.Hide()
    End Sub

    Private Sub cmb_type_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmb_type.SelectedIndexChanged
        refresh_grid(cmb_type.Text)
    End Sub
End Class

thanks in advance

nadiam 0 Posting Pro in Training

Laptop Details:

Asus
Windows 8.1 64-bit

Hi. Im having issues with my laptop lately, I kept getting BSOD with error PNP_DETECTED_FATAL_ERROR. I tried uninstalling softwares which I had previously installed but I still kept getting it so i did a reinstall of windows instead and now im having driver issues(with the Yellow Triangle + Exclamation Marks) :

http://imgur.com/a/Sa6KX

I know theres a way to get these drivers by getting the Hardware ID but I fear downloading and installing the wrong driver and messing it up more. And I dont know whether i should be having more than 1 High Definition Audio Device/PCI Data Acquisition and Signal Processing Control.

I have the Asus LiveUpdate but it didn't update anything except for the Intel Graphics Driver. So now im unsure how to go forward. I would download the drivers manually from ASUSTeK but like I said im not sure which is what. IT would be so much easier if there was a list of Hardware IDs and the associated driver or wtv. Could someone help me out?

  1. High Definition Audio Device
    HDAUDIO\FUNC_01&VEN_8086&DEV_2807&SUBSYS_80860101&REV_1000
    Provider : Microsoft

  2. SM Bus Controller
    PCI\VEN_8086&DEV_9C22&SUBSYS_130D1043&REV_04
    Manufacturer : Unknown
    Device Type : Others

  3. PCI Data Acquisition and Signal Processing Controller First
    PCI\VEN_8086&DEV_0A03&SUBSYS_20108086&REV_09
    Provider : Unknown

  4. PCI Data Acquisition and Signal Processing Controller Second
    PCI\VEN_8086&DEV_9C24&SUBSYS_130D1043&REV_04
    Provider : Unknown