kplcjl 17 Junior Poster

I hope the technology doesn't get too good, the image fuzzed text validation box to prevent reading text from images is unreadable enough as it is.

kplcjl 17 Junior Poster

What is the benefit of a bool property that just gets and sets a bool?
I know the benefit of only a get property or decisions that need to be made before you set a bool. I've seen examples using just get/set. I don't get it. What harm could making the bool variable public do?
(You can set it to null instead of a value, but you can do the same thing in a property if you don't check if value != null.)

kplcjl 17 Junior Poster

It's two different people, that's why. Bokac piggybacked on the original thread (which he probably shouldn't have).

Thanks, you are right

kplcjl 17 Junior Poster

Are you declaring a string and adding string variables to your list or are you running the function in the add? If you are working with strings, make sure what is passed is a string.
If it is receiving an object in the key that it can't figure out the order of, I'm surprised it even allows you to add it.
try casting it as string and add that.

kplcjl 17 Junior Poster

Come to think of it, the override would probably work, it probably resides in Win32, not Forms. You can't depend on the Form closing event processor, because it doesn't exist. Note that the loop you wanted to put in can't be put in. but a regular loop should continue working if you override the closing event.

kplcjl 17 Junior Poster

It's probabbly because you have a console app and Message is part of System.Windows.Forms eg not included in a console app by default.

Even if you add the assembly reference I don't think the WndProc will work unless you have a form.

Sorry, didn't read your code carefully. You should blow up because you are trying to override code that doesn't exist. If it doesn't after you put in the using statement, you may have the event process needed to do what you want. If it does, this definitely won't work. Putting in a request for user input may trigger a "code is not responding" error asking you if you want force shut-down and may lock you out of your app.

kplcjl 17 Junior Poster

I tried to use it, but getting an error

Error 1 The type or namespace name 'Message' could not be found (are you missing a using directive or an assembly reference?)

my application code is given here

...        }
}

...

That message tells you exactly what is wrong. The complete object address is: System.Messaging.Message Put using System.Messaging; at the beginning of your code or spell it out.

kplcjl 17 Junior Poster

This is ok, but I have something else in mind, when I check checkbox I need my textbox to be false right away... This code doesnt exetuce that.

That's completely opposite from what you said at first. You've gotten completely opposite answers to match your 2 requests. "right away"? The response should take less than 1 millisecond, how fast do you want it? Ten seconds before you decide to click the check box? Your problem has nothing to do with how fast. Your problem is to set coding to do what you want. By the way, is the ReadOnly property set correctly?

kplcjl 17 Junior Poster

Make a database of your friends. Store info like address, phone, picture and whatever you want. Make an input-output form as front end, include printing and whatever you see fit. That could keep you buzy for months, while learning alot.

Great suggestion! Simple interfaces, simple IO, not much calculations involved, almost infinite enhancements, possible commercial value.
Here's a tougher one. Solve a puzzle:
x x x x x x x
x35x31x33x
x x x x x x x
x30x37x29x
x x x x x x x
x34x31x27x
x x x x x x x
Sorry, don't know the author. This is a 7X7 array where you solve "x". "x" is 1 to 7, the "x" values surrounding the numbers need to add up to the number. No 1-7 number is repeated in any column or row.
This is so tough, I don't think you can solve it without hints. (I needed some. Not for the solution, for the win interface.) A classmate calculated it would take 6 months to solve the puzzle on 0.5 GFLOP machines. Using the worst possible method I could think of, on a 2GFLOP machine, it would take 213 thousand years just to set the numbers. (Set each of the "x"'s from 1 to 7 and then immediately verify if it solves the solution.) I have a routine that solves in under 9 minutes with my 1GFLOP machine.
PS There is a lot of degrees …

kplcjl 17 Junior Poster

Hey All

I have a multi-line text box that tells the user to perform an action. When the form loads, as the text box is the only control on the form, it is highlighted. This may be a silly question, but is it possible to disable the text box from being highlighted? Ideally it would be great if I could disable the text from being selected all together? Any suggestions would be great. Is there another control that would achieve what I'm trying to do?

Many thanks

Cameron

Sorry, didn't read your text closely. Glad the Label fixed your problem. When I bring up my app, the text box fields aren't highlighted or selectable at all using the read only attribute. But I have a button and a combo box on the form. When I use the combo box some of the text boxes become selectable. How do you navigate on your form if you give the user absolutely no way of communicating with the form?

kplcjl 17 Junior Poster

Hint:
1. READ ALL the PROPERTIES built into your objects.
2. UNDERSTAND them.
However, once you've read a property name like ReadOnly, how hard would that property be to understand?

kplcjl 17 Junior Poster

this.ReviewItems2_tbx.ReadOnly = true;

kplcjl 17 Junior Poster

Note if you set the transparent key (Last line of my code example.) to the Form's back color then they would both be transparent.

kplcjl 17 Junior Poster

The TextBox class dosn't support the Transparent
But I think you can get the same Effect by setting the backColor property for the textbox into the same color for form and ste the text box border to none

textBox1.BackColor =  this.BackColor;

How could that get the same effect? The default backcolor is NOT transparent. This works for me:

using System;
using System.Windows.Forms;
public class TransparentText : Form
{
	private TextBox Trans_tbx ;
	public static void Main(){Application.Run(new TransparentText());}
	public TransparentText(){
		Trans_tbx = new TextBox ();
		InitializeObjects();
		ResumeLayout(false);
	}
	private void InitializeObjects() {
	this.SuspendLayout();
        this.Trans_tbx.BackColor = System.Drawing.SystemColors.InactiveBorder;
        this.Trans_tbx.Location = new System.Drawing.Point(56, 48);
        this.Trans_tbx.Multiline = true;
        this.Trans_tbx.Name = "Trans_tbx";
        this.Trans_tbx.Size = new System.Drawing.Size(440, 400);
        this.Trans_tbx.TabIndex = 0;
        this.Trans_tbx.Text = "test 1";
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(544, 502);
        this.Controls.Add(this.Trans_tbx);
        this.Name = "TransparentText";
        this.Text = "test Transparent Text";
        this.TransparencyKey = System.Drawing.SystemColors.InactiveBorder;
	}
}
faeophyta commented: This helped a lot, thanks! +0
kplcjl 17 Junior Poster

OK, they count as the same name in the checker, not in the calling routine:

byte[,] vals = new byte[3,3];
        Numbrs.Numbers(vals);// was set_Numbers

...\My Documents>csc /reference:CourtneyNumbrs.dll /target:winexe Courtney.cs

Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

Courtney.cs(479,16): error CS1061: 'CourtneyNumbers' does not contain a definition for 'Numbers' and no extension method
'Numbers' accepting a first argument of type 'CourtneyNumbers' could be found (are you missing a using directive
or an assembly reference?)
Auugggg! It blows up like it's supposed to.
PS Numbrs is class 'CourtneyNumbers' . My first argument is really byte[,]!!!

kplcjl 17 Junior Poster

OK, I get it. "set_Numbers" and "Numbers" count as the same overloaded name using the byte[] signature and blew up.
So, C# is case sensitive but it ignores "_" as part of a routine's name. Anyone know why?
PS This code co-existed just fine:

public byte[,] Get_numbers {
        get {
		byte[,] vals = new byte[3,3];
		for (int i = 0;i < 3; i++) {
			for (int j = 0;j < 3; j++) {
				vals[i, j] = this.Cnumbrs[i, j].Solve;
			}
	        }
            return vals;
        }
    }
kplcjl 17 Junior Poster

Well, I am looking forward to some tool which woukld work like NGEN.exe and convert managed s..t into true machine code ???

As I said before you still haven't stopped anyone from decompiling your code.
My nephew has written an assembler routine that turbo-charges C# code. I don't know how it works and I haven't talked to him directly about it. I assumed that it converts C# into assembler and bypasses the overhead involved in running the MSIL code.

kplcjl 17 Junior Poster

There has never EVER been a way to stop decompiling code. (You can ALWAYS get the assembler code.)
Strong naming or using Authenticode on a strong named assembly WON'T protect you from someone decompiling your code. The only thing both will do is authenticate your modified stolen code didn't come from you. All you need is someone who cares enough to verify this. (Good luck on that!)
Sorry, Scott, if you don't distribute your software, you don't need to strong name it. (There are other very good reasons why you would want to do so.)
I can think of two ways to not distribute your software. Web Service, or ASP.Net. (or it's cgi equivalent.)
PS I loved the last few comments.

kplcjl 17 Junior Poster

OK, I agree that you can't change the opacity of a textbox. That makes sense, because it resides on a form. If you could change it it would just disappear on the form itself. The Form.Opacity Property allows you to change the visability of the whole form. Instead I suggest looking into the Form.TransparencyKey property. Now you set the background color of the Textbox and the background can disappear.

kplcjl 17 Junior Poster

How does a property that returns a byte[,] signature have the same parameter types as a function that returns a bool and has a passed byte[,] signature?

Here is the command:
...My Documents>csc /target:library /out:CourtneyNumbrs.dll CourtneyNumbrs.cs

here is the output:
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

CourtneyNumbrs.cs(25,17): error CS0082: Type 'CourtneyNumbers' already reserves a member called 'set_Numbers' with the
same parameter types
CourtneyNumbrs.cs(220,17): (Location of symbol related to previous error

Failed code on line 25:

public byte[,] Numbers {
  get {
    byte[,] sts = new byte[7,7];
    int i;
    int j;
    for (i = 0;i <7;i++) {
      for (j = 0;j <7;j++) {
        sts[i, j] = 0;
      }
    }
    for (i = 1;i <7;i += 2) {
      for (j = 1;j <7;j += 2) {
        sts[i, j] = Cnumbrs[i / 2, j / 2].Solve ;
      }
    }
  return sts;
  }
}

Reserved code on line 220:

public bool set_Numbers(byte[,] Numbrs) {
  byte o;
  bool ischanged = false;
  for (int j = 0;j < 3;j++) {
    for (int i = 0;i < 3;i++) {
      o = Numbrs[i, j];
      if (o > 14 && o < 50) this.Cnumbrs[i, j].Solve = o;
      else {
        ischanged = true;
        Numbrs[i, j] = Cnumbrs[i, j].Solve;
      }
    }
  }
  return ischanged;
}

In one case the property is Numbers, in the other, the function is …

kplcjl 17 Junior Poster

Back to my code example:

...
Update @tblDueVisits set WindowName=c.WindowName
from @tblDueVisits a
join @tbl1 b on a.DueDate=b.DueDate and UserID=@id
join @tbl2 c on ID1=ID2
...

OK, what is going on.
@tbl1 has an identity field and a list of every DueDate in @tblDueVisits where UserID=@id.
Since I didn't bother making a key for @tblDueVisits I instead made sure every DueDate was unique per UserID when I created the data so every date in both tables are an exact match.
@tbl2 has an identity field and a list of WindowNames that has the same number of rows in @tbl1 but from the static table data.
I am taking advantage of how an identity field works. Without modifiers, it will always start at 1 and always increase in value by 1. Therefore there will be a 1 to 1 match where ID1=ID2. Therefore there will also be a 1 to 1 where a.DueDate=b.DueDate and UserID=@id
So each WindowName is unique on each row after the update where UserID=@id.
I used 16 instead of 1 because it has multiple rows for the id in @tblDueVisits.

kplcjl 17 Junior Poster
...
--Get the different Visit Types
DECLARE cursorVisitNames CURSOR FOR SELECT TOP (@NumberOfVisits) VisitName FROM 
ORDER BY VisitName

...
FETCH NEXT FROM cursorVisitNames INTO @VisitType
...
		UPDATE tblWindows SET Visit = @VisitType WHERE UserID = 1

... tblWindows stores a pre-defined maximum number of records (say 10). This table will, at least, theoretically never change. ...

...

So, you have a table that will never change that you are updating... Huh. WHERE UserID = 1 when the table doesn't contain UserID and you are puzzled because it doesn't work? OK lets switch the tables in the cursor and the update so it matches your original text.

UPDATE tblDueVisits SET Visit = @VisitType WHERE UserID = 1

This table according to your statement is a two column key, so there are multiple records where UserID = 1, so of course every record gets set to the same visit type. You need to use BOTH key values in your where statement to identify 1 record you want to update.

You can set up a second cursor on tblDueVisits to retrieve the date where UserID = 1. Fetch next on it inside your existing loop (ONE time only --- DO NOT loop inside the loop.) and use both key fields to update only one record per loop.

I recommend you review the code I supplied. Toggle it to text, copy and paste into EM, fix my typo and run it. (Or don't fix it. You still get an example …

kplcjl 17 Junior Poster

This might be true on SQL 2005. I compared execution plans and the cost was 50/50 using functions and constants. There was no discernable difference in retrieval speeds, but I wasn't using a large table to do so.
What I do know is a user had defined a hash function and was using it on the other side from the column. It was taking 13 seconds to retrieve the data that matched the hash. Changed the routine to use a constant varchar variable and the response time went to 25 milliseconds. I also know I read a book that says the function is executed against every row in a table and shouldn't be used when the result is a constant value.
Of course the book and I can be out of date now.

kplcjl 17 Junior Poster

Hmmm, works for me. 'Course I did say it was from notepad

'This calculates and displays each floors occupancy rate.        
        Dim Occupancy(7) As Byte 'Why do you have an array that is going to be dropped        
        Dim TotOccupancy As Byte = 0 '240 is < 255 - can't overflow       
        Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim intCount As Byte
        Dim RoomCount As Integer 'User can say 2 billion and shouldn't overflow        
        'ListBox1.Items.Add    
        For intCount = 0 To 7
            RoomCount = -1
            While RoomCount < 0 Or RoomCount > 30
                strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
                If IsNumeric(strUserInput) Then RoomCount = strUserInput
                If RoomCount < 0 Or RoomCount > 30 Then
                    MessageBox.Show("Please enter a number >= 0 and <= 30")
                End If
            End While
            Occupancy(intCount) = RoomCount
            TotOccupancy += RoomCount
            decOccupancyRate = CDec(RoomCount) / 30.0
            ListBox1.Items.Add(decOccupancyRate * 100)
        Next
        strUserInput = "Total occupancy= " & TotOccupancy.ToString()
        ListBox1.Items.Add(strUserInput)
        decOccupancyRate = CDec(TotOccupancy) / 240.0
        ListBox1.Items.Add(decOccupancyRate * 100)
kplcjl 17 Junior Poster

Whoops set the count to -1 and check for less than 0.

kplcjl 17 Junior Poster

1. You can't add rates, it just doesn't work
2. When you display percentages, multiply by 100
3. You are processing and THEN checking for user errors and doing nothing about it.
Instead force them to get it right before going on.
4. Don't assume the user entered correct data
5. Keeping track of the occupancy per floor makes more sense than the rate

How about this? (Used notepad so it may be a bit weird.):

'This calculates and displays each floors occupancy rate.
        Dim Occupancy(7) As Byte 'Why do you have an array that is going to be dropped
        Dim TotOccupancy As Byte = 0 '240 is < 255 - can't overflow
       Dim decOccupancyRate As Decimal
        Dim strUserInput As String
        Dim decOccupancy As Decimal
        Dim intCount As Byte
        Dim RoomCount As Integer 'User can say 2 billion and shouldn't overflow
        'ListBox1.Items.Add

   For intCount As Integer = 0 To 7
      RoomCount = 0
      while RoomCount < 1 or RoomCount > 30
         strUserInput = InputBox("Enter the number of rooms occupied. Provide a value")
         if isnumeric(strUserInput) then RoomCount = strUserInput 
         if RoomCount < 1 or RoomCount > 30 then
            MessageBox.Show("Please enter a number greater than 0 and less than 30")
         End If
      end while
      Occupancy(intCount) = RoomCount 
      TotOccupancy += RoomCount 
      decOccupancyRate = CDec(RoomCount) / 30.
      ListBox1.Items.Add(decOccupancyRate*100)
   Next
   strUserInput = "Total occupancy= " & TotOccupancy.ToString()
   ListBox1.Items.Add(strUserInput)
   decOccupancyRate = CDec(TotOccupancy) / 240.
   ListBox1.Items.Add(decOccupancyRate * 100)
kplcjl 17 Junior Poster

Great! Now how do i get the area and the perimeter and are from clsRectangle to the area and perimeter boxes?

I assume you mean text boxes. There is a string property called "Text" that you can set. When you do, you can set that value to the returned property or function to display it and that shows up on your text box.

That's assuming the box is visable and has a contrasting forecolor so you can see the text. (Default) Since this is intended as a display box make it read only.

kplcjl 17 Junior Poster

I don't know if there are indexing routines, but you can set your starting position at 0. while it is less than the length of the string and the character at that position is blank go to the next starting position
set your ending length to 0 and while the length + position character are not blank and not past the end of the string you increment the length by 1. That identifies the length and position of the next word that you insert into a string array and increment the array by one.
Repeat that process using the new starting position until all the words are added to the array. Initalize a string with the last word in the array, from the next to last word to the beginning add a blank and that word to the string. This will not retain multiple blanks in the reversed string.

kplcjl 17 Junior Poster

1. It is poor design to have a character field value added to a table that is contained in another table instead of referencing the table (IE WindowID)
2. It is poor design to use (char) for fields that don't have a fixed number of characters
3. It is poor design to not use an order by statement when you aren't using selection criteria and only taking a piece of the information.
That said:

--initial test tables
SET NOCOUNT ON
DECLARE @tblUsers table (UserID int primary key, FirstName varchar(20), LastName varchar(20), BirthDate smalldatetime)
DECLARE @tblDueVisits table (UserID int, DueDate smalldatetime, WindowName varchar(20) null)
DECLARE @tblWindows table (WindowID int identity, WindowName varchar(20) null)
--initialize tables
declare @dtnow smalldatetime, @id int,@txt varchar(3),@rw int 
select @dtnow='20091105',@id=1
WHILE @id < 100
BEGIN
	set @txt=@id
	insert into @tblUsers values (@id, 'First' + @txt, 'LastName' + @txt, dateadd(year,-@id,@dtnow))
	insert into @tblWindows values ('WindowName'+@txt)
	select @id=@id*2,@rw=@@identity
	WHILE @rw > 0
	BEGIN
		insert into @tblDueVisits values (@id, dateadd(day,@id*@rw,@dtnow),null)
		set @rw=@rw-1
	END
END
set nocount off
--SELECT * FROM @tblUsers
--SELECT * FROM @tblWindows
--SELECT * FROM @tblDueVisits
SET NOCOUNT ON
-- Process requirement
SET @id=16
DECLARE @tbl1 table (ID1 int IDENTITY, DueDate smalldatetime)
DECLARE @tbl2 table (ID2 int IDENTITY, WindowName varchar(20) null)
INSERT INTO @tbl1 SELECT DueDate FROM @tblDueVisits WHERE UserID=@id
SELECT @rw=@@ROWCOUNT
INSERT INTO @tbl2 SELECT TOP (@rw) WindowName from @tblWindows
Update @tblDueVisits set WindowName=c.WindowName
from @tblDueVisits a
join @tbl1 b on a.DueDate=b.DueDate and UserID=@id
join @tbl2 c on ID1=ID2
select * from …
kplcjl 17 Junior Poster

Again, I sincerely hope you find it is IMPOSSIBLE to put a DB on my SQL server if I happen to link to your web site. There are enough security holes to drive a mack truck through without adding this one to it.
I'm kind of conflicted because I usually don't want someone to fail in their endevours, but I definitely hope you fail.

kplcjl 17 Junior Poster

Why are you creating constants when you can just use the date functions in the where clause?

SELECT sum(Salesamount)
   FROM Table
   WHERE salesdate BETWEEN   DATEADD(yy,DATEDIFF(yy,0,getdate()),0) --'First Day of Year'
   AND DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,getdate())+1,0))) --'Last Day of Year'

The key phrase is "functions in the where clause" As someone else has stated in this thread, this is a bad idea, expecially when selecting from indexed fields. First you are causing SQL to execute a process for every single row in the table. This increases CPU processing which slows down response. It does this for every row because functions are designed to give dynamic results and SQL doesn't realized this is producing a constant. By my count you are executing 6 functions. In a table with 20 million rows in it, that's 120 million executions and should take minutes if not hours to process.
That's if you are looking for 1 year or 1 hour, indexed or not indexed.
NEVER, EVER, EVER put functions that produce a constant value in SQL where clauses. (Unless you happen to like poor response and poor performance.)
PS I think my query is easier to read than yours with separate statements, 3 functions, sequentially executed.
PPS Whoops, miscounted ... 8 functions in yours, 3 in mine because I also removed the Midnight date error your query still has.

kplcjl 17 Junior Poster

Whoops when I modified the last select

delete from @tbl3 where Sum_id is null
select a.*,S_Ans from @tbl1 a left join @tbl3 b on a.c_code=b.c_code
order by c_code

for results
CSA00001 ADM00001 6825 CUS08349 NULL
CSA00002 ADM00001 6826 CUS08347 S=SUR00001,Q=1,A=4;S=SUR00002,Q=3,A=1;S=SUR00003,Q=7,A=6
CSA00003 ADM00001 6832 CUS08351 NULL
CSA02547 ADM00001 6824 CUS04150 S=SUR00001,Q=1,A=3;S=SUR00002,Q=4,A=7
I realized I'd typo'd the column value and had to correct the wrong value to be CSA00002

kplcjl 17 Junior Poster

1. Your format is almost unreadable. I suggest putting commas between column names and if your column name has a space, bracket it like <cus name>
2. You can't have a dynamic number of columns in a single result set
3. What you want isn't none too clear either.
4. if you want data combined from several rows into one row something like this:
CSA02547 S=SUR00001,Q=1,A=3;S=SUR00002,Q=4,A=7
CUS08347 S=SUR00001,Q=1,A=4;S=SUR00002,Q=3,A=1;S=SUR00003,Q=7,A=6
here is the code that will produce that result:

--Initialize two tables
declare @tbl1 table(c_code varchar(20), ou_code varchar(20), id int null,CName varchar(20))
insert into @tbl1
select 'CSA00001', 'ADM00001', 6825, 'CUS08349'
union select 'CSA00002', 'ADM00001', 6826, 'CUS08347'
union select 'CSA00003', 'ADM00001', 6832, 'CUS08351'
union select 'CSA02547', 'ADM00001', 6824, 'CUS04150'
declare @tbl2 table(surveycode varchar(20), c_code varchar(20), Qns_id int ,Ans_id int)
insert into @tbl2
select 'SUR00001', 'CSA02547', 1, 3
union select 'SUR00001', 'CUS08347', 1, 4
union select 'SUR00002', 'CUS08347', 3, 1
union select 'SUR00003', 'CUS08347', 7, 6
union select 'SUR00002', 'CSA02547', 4, 7

-- calculate cumulative total
declare @tbl3 table(id int identity primary key,
surveycode varchar(20), c_code varchar(20), Qns_id varchar(20),
Ans_id varchar(20),Sum_id int null, S_Ans varchar(max) null)
insert into @tbl3 (surveycode, c_code, Qns_id, Ans_id) select * from @tbl2 order by c_code,surveycode
update @tbl3 set S_Ans='S=' + surveycode + ',Q=' + Qns_id + ',A=' + Ans_id
update  @tbl3 set Sum_id=id where id in  (select min(id) from @tbl3 group by c_code)
while @@rowcount > 0
update a SET S_Ans=a.S_Ans + ';' + b.S_Ans, Sum_id=a.Sum_id+1
from @tbl3 a join @tbl3 b …
kplcjl 17 Junior Poster

Sorry, I didn't explain what I did.
"@dtyr=YEAR(GETDATE())" automatically casts the INT result of the YEAR() function into a 4 character string. The string format "YYYYMMDD" is globally recognized as a valid date format, no matter what format your local date setting uses. (IE "DD/MM/YYYY", or "MM/DD/YYYY", etc.) so "@dt1=@dtyr + '0101'" is the first day of the first month of this year at midnight. "DATEADD(YEAR,1,@dt1)" should explain itself, however if you use that in the BETWEEN statement it would include next year's data that started at January 1 midnight so "@dt2=DATEADD(MINUTE,-1,@dt2)" excludes next year's data. If you use DATETIME instead you would need to subtract 3 milliseconds. (If you did that and your comparison field was smalldatetime it would still round up to next year in the comparison.)

PS You should subscribe to SQLServerCentral, you get interesting articles e-mailed to you periodically. They just had an extensive article about this very issue.

kplcjl 17 Junior Poster

What sknake said, however he didn't give an example. You need to provide constants in the where clause, so calculate constants. If you are only recording current datetimes in the table you only need to find "WHERE SalesDate >= @dt1". If you are recording future dates as well or if you want to go to some year in the past use "WHERE SalesDate BETWEEN @dt1 AND @dt2".

DECLARE @dt1 SMALLDATETIME, @dt2 SMALLDATETIME, @dtyr CHAR(4)
SELECT @dtyr=YEAR(GETDATE()),@dt1=@dtyr + '0101',@dt2=DATEADD(YEAR,1,@dt1),@dt2=DATEADD(MINUTE,-1,@dt2)
kplcjl 17 Junior Poster

Thinking about it, a single would be precise up to around $10,000, an int32 would be precise to about $20,000,000. Maybe you should sum using int64? Put the calculations in a double and after dividing by 100 it would remain accurate for around $10 billion. Or keep the int64 and be accurate to around $40 million billion. Make the suggested temp field double.

kplcjl 17 Junior Poster

...

But what does this mean exactly? -> set it to your txtAmount, and then intAmount() to temp*100.

and this ->

do i=0 to ...
if Ischecking(i) then
TotalChecks+=1
TotalCheckAmount+=intAmount(i)
else
etc.
...
next i

TotalCheckAmount/=100
etc.

... "

1. I meant "temp = txtAmount.Text"
that implicitly converts a string into a single value. Then
"intAmount(intAmount.ubound) = temp * 100"
That converts the decimal portion of the single value implicitly into an integer value without loosing the decimal value of the change entered. If you had "intAmount(intAmount.ubound) = txtAmount.Text" and you had entered "45.46", the integer conversion would be 45. If you set it to temp and then multiplied by 100 the integer conversion would be 4546 even if you had entered "45.46135" which a conversion to single would retain. A single value would never exactly match "45.46" and retaining single values in an array would introduce rounding errors in the total sum.

For this:
do i=0 to ...
if Ischecking(i) then
TotalChecks+=1
TotalCheckAmount+=intAmount(i)
else
etc.
...
next i

"..." and "etc." means I used short-hand. I didn't even include the initialization of the variables. I meant TotalChecks would count the total number of checks entered. I could do this because Ischecking(i) was previously set to true when the user said they were entering a check and this was concurrently updated with intAmount and "ReDim"ed at the same times …

kplcjl 17 Junior Poster

Your existing ReDim process is fine. Your existing process of loading the data into arrays isn't fine, because the amount entered on your page isn't loaded into any array.
That needs to be corrected.

I had a suggestion for how to make that correction. Having two arrays, one for deposits and one for checks is OK but it has pitfalls associated with it. Having those two arrays AND an integer array saving the same data is redundant. I suggested having a boolian array added to the list and removing the two individual arrays. The advantage of this is that you can exactly mimic the chronological order of when checks and deposits were posted, it forces you to count checks and deposits separately, it integrates nicely with the database you are going to have to put up when you get to your ADO.NET training when you load a datatable into a dataset.

You don't have to have a Boolean array. When a check is drawn, make sure your IntAmmount is negative and a deposit is positive. (It would be a little hard to tell if the intent was a check or deposit if the amount is 0. Do you add an entry, if the user puts in 0?)

You are making a basic beginner’s mistake not initializing your sums before the do loop. You start out at 0, you put in a deposit of 1000, your deposit sum is 1000, and your checking sum is 0. You …

kplcjl 17 Junior Poster

@Thirusha correction, you can do DB connectivity with AJAX which is essentially JavaScript ;)

Sorry, I forgot about AJAX. It isn't just JavaScript. It is a combination of JavaScript and XMLA. One of the key phrases in the AJAX tutorial is "AJAX uses the XMLHttpRequest object". This is, in effect your cgi link I was talking about. The intent in the tutorial was to connect to a server that had your DB interface already built.
I assumed that the request was to create a database on the client since JavaScript is and remains client-side code only. I can't think of any valid reason for creating a database on the server-side. If he is dead-set on creating a DB on the client side, I suppose it is possible using AJAX, I still say it is impossible using JavaScript. You would need an unnamed SQL Server object running on the client, the person running the web page would need admin rights on SQL, you would connect using the local IP address, verify the DB doesn't exist on the client server and create it.
I sincerely hope and pray that using AJAX to create a DB on my server is impossible as well. I hate to think what a set of malware could do to me being able to connect to me, as me, just by setting up a web page. I hate what they can do now that requires a constant update of sentry software.

kplcjl 17 Junior Poster

Hello,

I'm a beginner in Visual Basic and I was wondering if it is possible to shorten twenty subs into only 1 sub.

example:

Private Sub box1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click
        Dim box1Click As Boolean = True
    End Sub

Private Sub box2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click
        Dim box2Click As Boolean = True
    End Sub

...

Private Sub box20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click
        Dim box20Click As Boolean = True
    End Sub

Thank you

1. Your example has "Handles object.Click" where the event is the same object (kist1) When you click on the kist1 object, I believe all the routines would be called just as well as one object. (I've never done so and see no purpose in doing so.)
2. Your examples creates a variable, sets its value, and then discards it without doing anything with it. That doesn't make sense, but you can do multiple things that don't make sense in one routine just as well as 20.
3. Since it passes "ByVal sender As System.Object", this routine is designed to handle multiple events, and is fairly easy to do in C#, but since I am a beginner, I too don't know how to direct multiple objects' one event type to one subroutine. I've got 9 routines that call one routine passing a Byte that tells me which object was called and it does the work. It would have been helpful to know how …

kplcjl 17 Junior Poster

Again, build a stored procedure in your DB. This procedure would have one parameter defined. (@SiteID int - Since you didn't specify type, I'm using int)
Delete your children records (Delete from Circuit where siteid=@SiteID etc.)
Delete your parent record (Delete from site where [site id]=@SiteID
As TomW stated, this won't affect the data entered in your dataset. You can either have your code remove the records from the table, sync up as he suggests, or have your interface incorrectly display data that should be deleted.
Neither of us are getting into validation techniques and processes you might use in the stored procedure.

kplcjl 17 Junior Poster

Hello,

I want to create database on SQL Server using Javascript and HTML. User will input following data. Server Name, Database name, File Sizes. When I will click "Submit" button database should be created on Selected server with entered name. I am using Client side HTML and Javascript.
we need to create database according to some standards thus we are preparing graphical user interface.
Quick response will be appreciated.

Thanks, Rahul

Impossible. Javascript is not designed to do work on another server, it is client side software that only runs on the client. Both HTML and JavaScript can post to a cgi which could do something like this. If the server name entered also hosts the cgi, Javascript could post the instructions to the server name's cgi and let it do the work. That or the client hosts the cgi and the user account has access to the server name.

kplcjl 17 Junior Poster

I second Tom's suggestion to use parameters. This assures the types are compatible and takes care of formatting as well.

Are you sure the datetimepicker will pick an exact date and time that you want? It's possible the query will never find the record even if it is formatted correctly.

kplcjl 17 Junior Poster

It is preferable to execute a procedure over letting your code have ANY access to tables directly.
I pulled the following script from help files looking up ExecuteNonQuery. Note the same type of query with SQL objects is available as well.

Public Sub CreateMyOdbcCommand(myExecuteQuery As String, _
myConnectionString As String)
    Dim myConnection As New OdbcConnection(myConnectionString)
    Dim myCommand As New OdbcCommand(myExecuteQuery, myConnection)
    myCommand.Connection.Open()
    myCommand.ExecuteNonQuery()
    MyConnection.Close()
End Sub

This is a simple query without parameters, but you can build the command with parameters as well. There are tools that will set it up for you as well. Read up on how ADO.NET works. Or you can build your command:
str = "Exec dbo.mysproc @custid=" & id.Tostring()
Again, using the built in commands is much better because it builds a type safe interface between the parameters you want to use and the values passed. For instance it would take "Exec dbo.mysproc @custname=xxyy", but it would fail to execute because xxyy wasn't quoted.

TomW commented: I agree overall and think you offer good advice but I do have a (respectfully) differing opinion about calling exec in a statement. A former bad practice that I used to do myself until proven as not being optimal. +1
kplcjl 17 Junior Poster

f radDeposit.Checked = True Then ...Else...
This seems like a single transaction desision, but you are applying all the values that were entered into either a deposit account or a check account running total which violates your instructions. Your deposit and checking arrays NEVER are updated
Put the updates into LoadArrayElements method and USE your arrays to store the value.

If you aren't storing the type of deposit or check why use intAmount which is never set?
Why don't you add an Ischecking(0) as boolian, set it based on radDeposit, have dim temp as single in LoadArrayElements, set it to your txtAmount, and then intAmount() to temp*100.

WHY do you have your count in an ARRAY, your ubound always has the total count.

Initalize!!!! your statistics before the loop. IE TotalDeposits=o TotalChecks=0 etc.
ONLY!!!! loop when requested IE

do i=0 to ...
if Ischecking(i) then
TotalChecks+=1
TotalCheckAmount+=intAmount(i)
else
etc.
...
next i

TotalCheckAmount/=100
etc.

Ever heard of debugging and STEPPING through your code?
You can actually WATCH your code getting changed.

PS You are BEGGING for an overindex error:
For i = 0 To intDepositAmount.GetUpperBound(0)
sglCheckAmount += intCheckAmount(i)

kplcjl 17 Junior Poster

"You will create a set of either collections or arrays"
"Set" means a collection in terms of English, not as a program object type.
You can choose collection"s" or array"s". This could be set up as Dim values(6,10) as string and redim the second value, but this violates your teacher's obvious request to separate them into collections or arrays that match the specific type of data. It looks like he is requesting you have 7 separate variables, so programming is specific to each variable's purpose.

kplcjl 17 Junior Poster

1. You are assuming your client is honest. It is safer to set up a string variable, verify What you get is numeric before going on.
2. Arrays are zero based indexes. You should start at 0 to N-1 and make sure N-1 is less than or equal to the declared value of your array.
3. You don't give your client an opportunity to change his/her mind and not give you N answers.
4. Finally to answer your question. txbName.Text = answer.ToString()

kplcjl 17 Junior Poster

Sorry, I replied to the code snippet instead of your question. Read above to see my comments.

kplcjl 17 Junior Poster

http://www.daniweb.com/forum58.html


1. You declare piccollect, assign it memory and then never use it.
2. You ask how to handle multiple picture boxes. Don't hardcode the picture box!!!!

Public Function GetByteArrayFromImage2(ByRef pb as PictureBox ) As Byte() Dim ms As New System.IO.MemoryStream With pb .Image.Save(ms, pb.Image.RawFormat) End With [\code] ...

[code=vb] Dim a(0) as Byte Dim b(0) as Byte a = GetByteArrayFromImage2(picturebox1) b = GetByteArrayFromImage2(Picturebox2) [\code] 3. "Return outBytes" terminates your logic, the last two statements are never executed. The only way they would execute is if the above statement was in an If statement and the false path is followed.[code=vb]
Public Function GetByteArrayFromImage2(ByRef pb as PictureBox ) As Byte()
Dim ms As New System.IO.MemoryStream
With pb
.Image.Save(ms, pb.Image.RawFormat)
End With
[\code]
...

Dim a(0) as Byte Dim b(0) as Byte a = GetByteArrayFromImage2(picturebox1) b = GetByteArrayFromImage2(Picturebox2) [\code] 3. "Return outBytes" terminates your logic, the last two statements are never executed. The only way they would execute is if the above statement was in an If statement and the false path is followed.[code=vb]
Dim a(0) as Byte
Dim b(0) as Byte
a = GetByteArrayFromImage2(picturebox1)
b = GetByteArrayFromImage2(Picturebox2)
[\code]
3. "Return outBytes" terminates your logic, the last two statements are never executed. The only way they would execute is if the above statement was in an If statement and the false path is followed.

kplcjl 17 Junior Poster

Been there, done that. Doesn't really require DNA encoding, just experience. At my former company, they expected a 3 person team to build a brand new application in 3 months. A. We couldn't touch a DB, but we could tell someone else what we wanted. B. We had to use a program none of us had even looked at. C. On an OS none of us had used before. (I think it was written in 1970.) D. Building forms on a prehistoric dinosaur of a forms language none of us had used before. We made it, no thanks to the DB team we worked with.