|
KA National Marker wrote: I dont believe I'm ignoring the rec variable.
Where do you reference it within the loop ? You reference d1 and d2, which are never changed. So, you will end up with the same values each time.
For Each rec In dgOrderReport.DataSource
Select Case DatePart("w", d1)
Case 1
subtract = subtract + 1
Case 7
subtract = subtract + 2
End Select
Select Case DatePart("w", d2)
Case 1
subtract = subtract + 2
Case 7
subtract = subtract + 1
End Select
absday = DateDiff("d", d1, d2) + 1 - subtract
fncGetDays = absday - CInt(2 * (absday \ 7))
If fncGetDays < 0 Then fncGetDays = 0
'x = x + 1
Next rec
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I now understand exactly what you mean about not referencing 'rec' within my loop - I wasn't able to successfully reference it because of the lack of knowledge I have with the Class I was using so I changed the code just a bit -
I decided to use a the currency manager to count each row, and I'm now using a do while - now my problem is my specified cast is not valid - which I'm assuming is because I'm using the wrong class for rec to compare it to my datagrid...Help will be great - Thanks...
Dim rec As Object
Dim cm As CurrencyManager = CType(BindingContext(dgOrderReport.DataSource), CurrencyManager)
Dim rowcount As Integer = cm.Count
Dim row As Integer = 0
Do While row < rowcount
For Each rec In dgOrderReport.Item(row, 3)
Select Case DatePart("w", d1)
Case 1
subtract = subtract + 1
Case 7
subtract = subtract + 2
End Select
Select Case DatePart("w", d2)
Case 1
subtract = subtract + 2
Case 7
subtract = subtract + 1
End Select
absday = DateDiff("d", d1, d2) + 1 - subtract
fncGetDays = absday - CInt(2 * (absday \ 7))
If fncGetDays < 0 Then fncGetDays = 0
row = +1
Next rec
Loop<code></code><code></code>
Thank You
|
|
|
|
|
Hi All,
I have list of html files for online documentation of VBA.
Can any one tell me how to generate *.chm file from html files.
I am trying to get Dynamic Help using Ctrl+F1 using chm file.
Also how to link the chm file to Ctrl+F1 key?
Thanks In Advance.
|
|
|
|
|
Look for .chm compiler. I think it may allow you to convert .html, I'm not 100% on that.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
|
'''
''' Populates the DataGridView
'''
Private Sub PopulateDataGridView()
' Set the column header names.
userAccessGrid.ColumnCount = 5
userAccessGrid.RowsDefaultCellStyle.BackColor = Color.White
userAccessGrid.RowHeadersVisible = True
userAccessGrid.Name = "User Access Grid"
userAccessGrid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised
userAccessGrid.CellBorderStyle = DataGridViewCellBorderStyle.Raised
userAccessGrid.ColumnHeadersHeight = 20
' Initialize basic DataGridView properties.
userAccessGrid.Dock = DockStyle.Fill
userAccessGrid.BackgroundColor = Color.LightGray
userAccessGrid.BorderStyle = BorderStyle.Fixed3D
userAccessGrid.Columns(0).Name = "AccessLevelDescription"
userAccessGrid.Columns(0).DataPropertyName = "AccessLevelDescription"
userAccessGrid.Columns(0).Width = 40
userAccessGrid.Columns(0).HeaderText = "Access Level Description"
userAccessGrid.Columns(0).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(1).Name = "NoAccess"
userAccessGrid.Columns(1).DataPropertyName = "NoAccess"
userAccessGrid.Columns(1).Width = 40
userAccessGrid.Columns(1).HeaderText = "No Access"
userAccessGrid.Columns(1).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(2).Name = "ReadOnly"
userAccessGrid.Columns(2).DataPropertyName = "ReadOnly"
userAccessGrid.Columns(2).Width = 40
userAccessGrid.Columns(2).HeaderText = "Read Only"
userAccessGrid.Columns(2).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(3).Name = "NormalAccess"
userAccessGrid.Columns(3).DataPropertyName = "NormalAccess"
userAccessGrid.Columns(3).Width = 40
userAccessGrid.Columns(3).HeaderText = "Normal Access"
userAccessGrid.Columns(3).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(4).Name = "TotalAccess"
userAccessGrid.Columns(4).DataPropertyName = "TotalAccess"
userAccessGrid.Columns(4).Width = 40
userAccessGrid.Columns(4).HeaderText = "Total Access"
userAccessGrid.Columns(4).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.SelectionMode = DataGridViewSelectionMode.CellSelect
userAccessGrid.MultiSelect = False
userAccessGrid.BackgroundColor = Color.LightBlue
userAccessGrid.ColumnHeadersDefaultCellStyle.Font = New Font("Arial", 8, FontStyle.Regular)
'--------------------------------------------------------------------------------------------
Dim appdesc_selectStatement As String = "Select access.level, pas_appitem FROM(access)Where access.uname = '' ORDER BY appitem"
Dim level_selectStatement As String = "Select accitem.appdesc, acclevels.level, accitem.appitem FROM(accitem, acclevels, access)Where access.uname = '' And accitem.appitem = access.appitem And access.level = acclevels.level Order By accitem.appitem"
Dim dt_Appdesc As New DataSet()
v = clsDataAnalyzerJetOleDb.MSAccessOleDb.PopulateDataSet(appdesc_selectStatement)
Dim dt_Level As New DataSet()
dt_Level = clsDataAnalyzerJetOleDb.MSAccessOleDb.PopulateDataSet(level_selectStatement)
Dim ds As DataSet = New DataSet()
Dim Dt_UserAccessDataSet As New DataSet()
Dim DescriptionColumns() As DataColumn = New DataColumn() {ds.Tables(0).Columns("appitem"), ds.Tables(0).Columns("appdesc")}
Dim AccessLevelColumns() As DataColumn = New DataColumn() {ds.Tables(1).Columns("level"), ds.Tables(1).Columns("desc")}
Dim Tran_Detail As New DataRelation("DescriptionColumns", ds.Tables(0).Columns("AccessLevelDescription"), AccessLevelColumns(1).Columns("No Access", "ReadOnly", "NormalAccess", "TotalAccess"))
'Dim tablearray() As DataTable = New DataTable(3) {}
'tablearray(0) = dt_Appdesc.Tables("appitem")
'tablearray(1) = mySecondDataSet.Tables("AnotherTable")
'tablearray(2) = myThirdDataSet.Tables(0)
'get a DataTableReader over these tables
'myDataTableReader = myFirstDataSet.GetDataReader(tablearray)
' Section for filling the Fields after the Data has been looped and read into the Grid
Dim OleDBConn As OleDbConnection = New OleDbConnection(MSAccessOleDb.ConnectionString())
OleDBConn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("appdesc_selectStatement", dt_Appdesc)
Dim daTransactions As OleDbDataAdapter = New OleDbDataAdapter(cmd)
daTransactions.Fill(ds, "dt_Appdesc")
Dim cmdDetails As OleDbCommand = New OleDbCommand("level_selectStatement", dt_Level)
Dim daTransactionDetails As OleDbDataAdapter = New OleDbDataAdapter(cmdDetails)
daTransactionDetails.Fill(ds, "dt_Level")
DataRelations(Of String, DescriptionColumns(), AccessLevelColumns(), Boolean)()
Dim dx As New DataGridViewTextBoxColumn() = New DataGridViewTextBoxColumn()
'Pass in ds as DataSet, and "Transactions as TblName
Dim userAccessDataRow As DataRow = dt_Appdesc.NewRow()
Dim userAccessDataAdapter As New OleDbDataAdapter()
For Each userAccessDataRow As DataRow
Dim i As Integer
For i = 0 To dt_Appdesc.Rows.Count - 1
'Loop through Query B
'For each Row in DataTableB
For Each userAccessDataRow As DataRow In userAccessTable.Rows
'The level from the query associates to the proper checkbox in the row
accessQuery = accessQuery + 1
'Loop Through Query A's DataTable
i = 0
For Each userAccessDataRow In userAccessTable.Rows
userAccessTable.Columns(1)(0) = userAccessDataRow(0)(1).value
'i = i + 1 'So, that we continue looping
'Level2 = Row(0).value
'If Level2 = Level1 Then 'Set the level
CheckBox in Column(1)
Exit For
Exit For
Next
Next
Next
Next
Try
' Section for filling the Fields after the Data has been looped and read into the Grid
If dt_Appdesc.Rows.Count = 0 Then
Dim OleDBConn As OleDbConnection = New OleDbConnection(GetOleDBConn())
OleDBConn.Open()
userAccessDataAdapter.SelectCommand = New OleDbCommand(appdesc_selectStatement, OleDBConn)
userAccessDataAdapter.Fill(dt_Appdesc)
userAccessDataAdapter.InsertCommand = New OleDbCommandBuilder(userAccessDataAdapter).GetInsertCommand()
userAccessDataRow("uname").Trim()
dt_Appdesc.Rows.Add(userAccessDataRow)
OleDBConn.Close()
OleDBConn.Dispose()
Else
Throw (New Exception("Error attempting to insert duplicate data."))
End If
Catch messerr As Exception
Call ShowErrorMessage(messerr, "listboxUserGroup_SelectedIndexChanged", "frm_security")
End Try
' Add the rows to the DataGridView.
Dim rows() As Object = {}
Dim rowArray As Object()
For Each rowArray In rows
userAccessGrid.Rows.Add(rowArray)
Next rowArray
' Adjust the row heights so that all content is visible.
userAccessGrid.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)
End Sub
Here's my nasty 150 line DataSet, DataRelation, DataObject, DataBullshit problem. As you can tell, this isn't the first day that I've been working on this function. If you have any bones to through in my general direction, I'd be incredibly grateful. My goal is to get a two Datasets and combine them after I take the user access level and turn it sideways. Then populate the gridview, then I'm going to write back to the database from the selected values.
Gridview looks like
Appdesc NoAccess Read-Only Normal Total Access
blah blah X X X X
blah blah X X X X
|
|
|
|
|
Is this written in Access VB, VB6 or VB.NET ? A lot depends on the answer to this question. You are right about one thing though, this is nasty. (You have actually hard coded the entire gridview.)
I will throw you this bone: get .Net Studio, put a datagrid on a form, link it to your dataset, and populate the dataset. Of all the code, you will only have to write about 20 lines, if that much.
Necessary changes can be made directly to the dataset structure, or the database, and your grid will adapt itself to the changes.
If you are already using a version of .net studio, then you really need to let go of these old vb6 habits.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi everybody. I'm using enterprise library 3.1 and vb 2005. I want to build a data access layer but I don't know where I can start.
It's my first time using patterns so I hope you can help me.
I had installed and build the application block but I don't know how use them.
JESHU
-- modified at 17:47 Tuesday 21st August, 2007
|
|
|
|
|
You are going to have to start with the documentation (and lots of it). The enterprise library is a pretty big beast. Even just in the Data Access Block theres a lot to read up on, much more than someone could put in a post here. Theres a few examples on the internet, but most of them seem to use the DAB for one function only: ExecuteDataSet(...) Finding a good guide could be tricky.
If you need to get a data layer up and working in a hurry, I suggest you use Diamond Binding, linked in my signature. That will do 90% of the work for you.
|
|
|
|
|
I linked in your signute and read about Diamond Binding.
It is a tool? It is code block?
So, It's free or I have to pay something?
I am building a data layer but I need to understand how it works.
There are many examples with enterprise library and dataaccess layer but There isn't any with both.
Any advice?
Thanks in advance
JESHU
|
|
|
|
|
Hi JESHU,
In answer to your question, it is an addin for Visual Studio and a runtime library. If you flip though the example on the website, you can see basically what it does.
And yes, depending on what you will use it for, there is a free edition that you can download.
A quick summary of how it works (which is covered in more detail in the examples, and the getting started guide) is that it maintains the active record classes for you, with the database fields as properties - a lot like how the form designer gives you a class with all the controls available in a partial class. Then you can just use them out the box like a normal business layer, Dim foo as Invoice = Invoice.Find(123), or add your own code. So it takes care of the data <--> business objects part of your application for you.
I encourage you to give it a try - it will save you a lot of time
|
|
|
|
|
Hi,
I have a problem with the memorystream.
I read a file in memorystream .
The length of the file is 178 and the length of the memorystream is 160.
And when I convert the bytes from memorystream in string I see that the file is not complete.
Can I lose bytes or the memorystream doesn't hold all the information?
Please help me because I don't have a clue.
Thanks.
|
|
|
|
|
Standard question #2. What does the code look like that you're using to get the file into the memory stream?
|
|
|
|
|
Dave Kreskowiak wrote: Standard question #2. What does the code look like that you're using to get the file into the memory stream?
No. Standard question #2 is:
What error message do you get?
You want standard question #3:
What does your code look like?
---
single minded; short sighted; long gone;
|
|
|
|
|
my code is:
Private Function DecryptFile(ByVal strInputFile As String, _<br />
ByVal bytKey() As Byte, _<br />
ByVal bytIV() As Byte) As String<br />
<br />
Dim strBuilder As New StringBuilder<br />
Dim mem As MemoryStream = New MemoryStream()<br />
'Setup file streams to handle input and output.<br />
fsInput = New System.IO.FileStream(strInputFile, FileMode.Open, _FileAccess.Read)<br />
mem.SetLength(0)<br />
'Declare variables for decrypt process.<br />
Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing<br />
Dim lngBytesProcessed As Long = 0 'running count of bytes processed<br />
Dim lngFileLength As Long = fsInput.Length 'the input file's length<br />
Dim intBytesInCurrentBlock As Integer 'current bytes being processed<br />
Dim csCryptoStream As CryptoStream<br />
'Declare your CryptoServiceProvider.<br />
Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged<br />
<br />
csCryptoStream = New CryptoStream(mem, _<br />
cspRijndael.CreateDecryptor(bytKey, bytIV), _<br />
CryptoStreamMode.Write)<br />
<br />
'Use While to loop until all of the file is processed.<br />
While lngBytesProcessed < lngFileLength<br />
'Read file with the input filestream.<br />
intBytesInCurrentBlock = fsInput.Read(bytBuffer, 0, 4096)<br />
'Write output file with the cryptostream.<br />
csCryptoStream.Write(bytBuffer, 0, intBytesInCurrentBlock)<br />
'Update lngBytesProcessed<br />
lngBytesProcessed = lngBytesProcessed + CLng(intBytesInCurrentBlock)<br />
<br />
End While<br />
<br />
Dim result As Byte() = mem.ToArray()<br />
<br />
Dim valu As String = System.Text.Encoding.ASCII.GetString(result)<br />
|
|
|
|
|
You forgot to close the cryptostream so that it gets flushed. The stream is encrypted in blocks of a set size (probably 32 bytes in this case), which means that you only get the completed blocks if you don't close the stream.
---
single minded; short sighted; long gone;
|
|
|
|
|
thanks.
I resolved the problem,now it works.
|
|
|
|
|
I am using some code that is explained in this article:
http://www.codeproject.com/useritems/VBFileAssociation.asp[^]
to check when my program loads to see if my own special file type has been associated with my program, and then associating it if it is not.
However, I want to make it so that when a user is looking at files through windows explorer, any files of my special type (my own file extension) will have the same icon as my program. The code in the above article did not do that for me. Does anyone know how this is done?
|
|
|
|
|
Hello,
My problem.
we have a legacy unix system that perdiodically writes files to a subdirectory ( a repeating job runs every few minutes and drops the files).
There are sets of files so there may be setA File1to3 and SetB file1to8.
This is absoluely THE ONLY WAY the unix system will transfer the files (no http pushes or web services or anything else)
I have to write an interface that runs a periodic VB net job which will read the contents of the subdirectory and if a complete set is present move that set from the subdir.
Of course my job and the unix job could be running at exactly the same time so I cant just find a find and move it out , because the file may still be being copied from unix as I try and copy it.
I am looking for a safe way of handshaking those files.
I was thinkinng the unix system could write a lock file, which stops my job looking in the subdir,copies the unix files and deletes the locking file.
BUT ok here is where I admit to lying slightly - it isnt one unix system its 4 and there is also 1 windows xp system that works in the same way (sigh!)
So I could use 5 locking files and if any are present not do anything But what if one of those unix systems crashes after writing a lock file , then the whole process is stuffed (er thats a technical term I believe!).
So what I am really looking for is process logic which is a safe and simple way of getting my VB Net interface to read files in sets which have been delivered to the same subdirectory from different sources (and yes it must be the same subdirectory - The network security people have only opened this 1 subdir and no child subdirs are permitted - They must be a different breed of people - still...)
is there a way of telling if a file has finished being copied to a subdir - ie its 12M in length - I look at it whene only 4 M has been copied......
Thanks in advance
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
This will only work if each of the files are written all at once... Your app could look for a complete set of files, and if there isn't one, reset and wait for a bit to check again. If there IS a complete set of files, wait an appropriate amount of time for the files to be completely written.
There are problems with trying to open files to check if another process is writing to them. If the other process opens the files, allowing shared access to it, your attempt at opening the file will always succeed, so that's useless in trying to find out if the other process is finished.
Also, if the other process opens the file, writes some data, closes it, then reopens the file, writes some more data, closes it, ... Rinse and Repeat ad nauseum ... then this method will also fail again because you might successfully open the file between writes by the other app.
You've already pointed out the flaw of using lock files, but it's not as bad as you think. When the unix app restarts, it should NOT look for and kill it's lock file if there is one. It should maintain the lock so the data can be backed out or rewritten, THEN kill the lock file.
MartyK2007 wrote: is there a way of telling if a file has finished being copied to a subdir
There's no "100% safe" way of doing this using files...
|
|
|
|
|
hello,
Dave Kreskowiak wrote: wait an appropriate amount of time for the files to be completely written
can you define and appropriate amount of time. Files can be up to 6M , network drive response could be crap due to bandwidth issues etc.
Also does having 10 files mean the codes waits 10 periods or waits 1 period and hopes all 10 files have finished copying.
if the latter:
What happens if you see set A File 1 , wait 10 minutes (say for this example - I know in reality it will be a lot less) and Set B File 9 starts to arrive in the tenth minute. You can now copy set A file 1 no problem but then Set B file 9 is still copying so you crash whne you try and grab it.
If the former then it slows the overall throughput down dramticaly
Dave Kreskowiak wrote: Also, if the other process opens the file, writes some data
In theory that wont happen in my scenario all, the Set A wont be copied to the directory until all the files have been updated.
Dave Kreskowiak wrote: It should maintain the lock so the data can be backed out or rewritten
that implies that some thought has been given by our unix team to crashes etc and that they have coded something like that - for which I am doubtfull.
It would mean a change to the reboot process of all the unix systems and the windows system. I am not sure I can get the resource authorised for that.(you know how it is)
You dont have a decent "Pattern" for doing this anywhere do you??
Thanks
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
MartyK2007 wrote: can you define and appropriate amount of time.
Nope. That's where you have to define it based on your environment, the number of files in the set, network speeds, ...
MartyK2007 wrote: Also does having 10 files mean the codes waits 10 periods or waits 1 period and hopes all 10 files have finished copying.
Again, that's up to you. Only you know how long it takes for a complete set to show up. How long has the biggest set taken to show up?
Basically, you're looking for an entire set of files to show up before you start copying/moving the files in that set. If you want the ral answers as to how this is going to work, and not work, you're going to have to write some test code to test to see if you can open these files for exclusive access WHILE they're being written to this folder. This is the only way you're going to know if your test will break the other app, or if the technique will work at all.
MartyK2007 wrote: In theory that wont happen in my scenario
Say that again around professional developers and watch how fast they point and laugh at you.
MartyK2007 wrote: that implies that some thought has been given by our unix team to crashes etc and that they have coded something like that - for which I am doubtfull.
This statement alone turns this project into an impossible task to make run "100% safe".
MartyK2007 wrote: You dont have a decent "Pattern" for doing this anywhere do you??
I'd do some testing before I get to any design patterns. It's pretty much a waste of time if the technique you're trying to use doesn't work. Figure out what technique is going to work, then ytou can design a framework around it.
|
|
|
|
|
Hi Martin
We get our mainframe to follow a strict protocol:- FTP (or file-copy) the big data file into the folder (e.g. "MyData20070821_1.dta").
- FTP a zero-sized flag file with the same basename (e.g. "MyData20070821_1.flg").
Our reeeeally cutting-edge VbScript program then periodically looks for flag files in the input folder. It can then safely assume that the associated data file(s) have been successfully uploaded.
I would recommend that the file names should be uniquely-named. Ours weren't so we appended a unique ID number into each data file's name (and we tagged any resulting database records with that id too). We move all processed files into an "archive" folder as an audit trail - and also so we can potentially rerun files if we need to restore our database for any reason.
We prototyped an alternate mechanism a couple of years. We found that FTP placed an exclusive-write lock on the uploading data file - so we added some logic to obtain a read-lock on the file. If our lock failed then we could assume that FTP was still manfully trying to upload the file.
Hope that helps.
Andy
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".
|
|
|
|
|
hey
that makes sense and may help
thanks
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
Hi,
My proposal is along the lines of Andy's:
- let the first system create the files of a set, using unique file names
(every OS has a function to provide these, if not include datetime up to
milliseconds and wait 1 millisecond after creating a file)
- when the set is complete, let the first system create a content file
listing all the files of a set;
this file too has a random filename but needs to be recognizable (maybe
by its first char, or by an extension)
- let the second system periodically look for content files; if one is found,
"execute" it, and delete all related files.
- to make sure the content file is complete, have it end on a sentinel
(a fixed line of text, file is invalid if sentinel is missing);
alternatively keep it as short as a single disk sector (512B), then it
can not be a partial file!
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|