|
i have one program.in that n number of boxes.need to arrange the box according to the size.first biggest box is the outer box.that we need to place in (0,0) position.Rest all the boxes i need to arrange inside the box from biggest to smallest.biggest in the bottom.smallest in the top.if the outer box height is more than the inner box arrange near to the bigger box of the bottom.
can anybody help me
|
|
|
|
|
Sounds very much like a homework assignment to me. We don't do homework for you - it's set for a reason, to test what you know, not what a random bunch of strangers on the Internet know. What have you tried so far? What code do you have?
This space for rent
|
|
|
|
|
I've seen a post from Luc Pattyn describing it as a "knapsack problem". Found the thread here[^], and contains a link to wikipedia detailing different sacks and some pseudo-code.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi, I am processing Excel files, I need to convert the .xls files that are 32 bit into 64 bit .xlsx files and supply them to the SSIS Packages for Processing. I need to write it in .Net code, can anybody please help me in this regards if its possible or not? I am also searching on google, if you can help me it will save me, as it is needed little urgently. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
They're not 32-/64-bit files. The .xls files are old-style Excel 2003 files, and the .xlsx files are the newer Excel 2007 / OpenXML files.
If you're writing an interactive desktop application which will be run on a computer with Office 2007 or later installed, you could use Interop to convert the files:
var app = new Microsoft.Office.Interop.Excel.Application();
var wb = app.Workbooks.Open(sourceFilePath);
wb.SaveAs(Filename: destinationFilePath, FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
wb.Close();
app.Quit();
Otherwise, you'll need to use a library which supports both formats - for example, NPOI[^]. It's not trivial, but this StackOverflow answer[^] has an example.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I am getting an issue in my Application that's reading Excel files and Oracle Database, it was working before it started giving problems suddenly.
I am thinking probably the drivers are the issue, but want to know which drivers are installed on the machine.
Can somebody please let me know how can I find the version and mode (like 32 or 64 bit) Oracle and Office Drivers installed on my machine. I am also searching on the google, but if you can help me earlier than that, it would be a great help my friends. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
I can see you, sitting on the couch, feet on the coffee table, typing this on your phone, while watching tv...
It took more effort to type this message than to go into the Control Panel; Admin; etc.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
It is possible that the OP was not expressing himself perfectly! If it was, indeed, the software on his machine (i.e. the one he was sitting in front of) about which he was asking, your response was fairly appropriate. I suspect, however that he is trying more generally to identify the installed Oracle and Office versions on a user's system from within a running Application. I haven't looked into this for Oracle, but I have for Office, and it is highly non-trivial, since Microsoft doesn't keep comprehensible Office version information in any standard location. If that is what he needs, I suggest that he posts back to confirm this, and I will try to offer some suggestions.
|
|
|
|
|
Dim Number1 As String = "2812"
Dim Str, strTemp, strReturn As String
Dim x As Long
Str = "ATDT" & Number1 & "R"
For x = 1 To Len(Str)
strTemp = Hex$(Asc(Mid$(Str, x, 1)))
If Len(strTemp) = 1 Then strTemp = "0" & strTemp & ","
strReturn = strReturn & Space$(1) + "&H" & strTemp
Next x
strReturn = stReturn & " &HD"
Dim Num as integer = Convert.ToInt32(strReturn)
buffer = {Num}
frmMain.SerialPort1.Write(buffer, 0, buffer.Length)
Threading.Thread.Sleep(500)
buffer = {&H41, &H54, &H44, &H54, &H32, &H38, &H31, &H32, &H52, &HD}
frmMain.SerialPort1.Write(buffer, 0, buffer.Length)
Threading.Thread.Sleep(500)
Next x
modified 1-Sep-17 8:09am.
|
|
|
|
|
Problem 1:
Convert.ToInt32 expects a string containing a single numeric value, and returns a single Integer value.
You are trying to convert a string containing multiple numeric values, and expecting an array of Integer values.
You would need to split the string, and convert each part separately.
Problem 2:
Convert.ToInt32(ByVal value As String)[^] does not allow you to use a Hex prefix. Neither the VB prefix (&H ) nor the C# prefix (0x ) will work.
Instead, you need to remove the prefix and call the overload which accepts the base you want to convert from:
Convert.ToInt32(ByVal value As String, ByVal fromBase As Integer)[^]
(NB: The C# prefix would work with this overload, but the VB.NET prefix won't.)
Dim parts() As String = strReturn.Split(" "c)
Dim buffer() As Integer = Array.ConvertAll(parts, Function(p) Convert.ToInt32(p.Substring(2), 16))
Problem 3:
You're converting the values to Integer , but Write[^] expects an array of Byte values.
It would be much simpler to use the Encoding[^] class to convert the string to a series of bytes:
Dim Number1 As String = "2812"
Dim Str As String = "ATDT" & Number1 & "R" & Chr(&HD)
Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(Str)
frmMain.SerialPort1.Write(buffer, 0, buffer.Length)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 19-Sep-17 7:38am.
|
|
|
|
|
Thanks, I guess I was just over complicating it.
|
|
|
|
|
Richard Deeming wrote: Convert.ToInt32 does not allow you to use a Hex prefix. Neither the VB prefix (&H ) nor the C# prefix (0x ) will work.
Huh?
"If fromBase is 16, you can prefix the number specified by the value parameter with "0x" or "0X"."
Convert.ToInt32 Method (String, Int32) (System)[^]
|
|
|
|
|
Only on the overload that takes the "from base" parameter. That's not the overload the OP was calling.
Convert.ToInt32("2A", 16)
Convert.ToInt32("0x2A", 16)
Convert.ToInt32("&H2A", 16)
Convert.ToInt32("0x2A")
Convert.ToInt32("&H2A")
I'll edit the message to clarify.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Getting this error.
System.AccessViolationException was unhandled
Message: An unhandled exception of type 'System.AccessViolationException' occurred in AxInterop.ShockwaveFlashObjects.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
When I have Adobe Flash security updates installed.
Using this code
Flash.Movie("movie.swf")
Flash.Play
Then
Flash.LoadMovie(1, "crash.swf") 'Crashes when Adobe Flash is updated, doesn't allow top layer SWF to interact with Movie/base.
To load multiple SWF layers at same time crashes. I'm guessing the security update did something so you can't write layered SWF code to the original SWF's memory. I don't know why this is, but is there any fix or will there be one? This has been like this for about a year now, and it doesn't seem like it'll be addressed.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at ShockwaveFlashObjects.IShockwaveFlash.LoadMovie(Int32 layer, String url)
at AxShockwaveFlashObjects.AxShockwaveFlash.LoadMovie(Int32 layer, String url)
at AEDab.Form1.ListBox1_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\UDA\Documents\Visual Studio 2013\Projects\uh\uh\Form1.vb:line 77
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
|
|
|
|
|
You probably need to report this to Adobe and check with them for a fix.
|
|
|
|
|
I've tried but I've never gotten a response. This has been over a year so far, multiple attempts to contact but all have been ignored.
|
|
|
|
|
Hi,
I am getting the following error no matter what path I am giving for this file to load into a Table in the Database from Excel using Jet Engine
The path I have tried are
1. I kept the file on my local machine to run the Package from my Local machine, it said invalid Path (C:\Users\aaleem01\Desktop\Project Documents\Tucker Package\Daily Facets Report 8.21.17.xls)
2. I kept the shared drive/folder, still it gave me in valid file path (Z:\FileWatcher\Daily Facets Report 8.21.17.xls)
3. Then I dropped the file on the Server where Sql Server instance is running and used that path in creating the Connection string for Excel, still it gave me the same error
Can anybody tell me what could be wrong in my file Path, I am trying to execute a Script Task in which I load data from Excel file into a Sql Server Table.
Here is how my Code looks like:
string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Dts.Variables["ExcelFullPath"].Value + ";Extended Properties=Text;";
string sqlConnectionString = "Data Source=" + Dts.Variables["ServerName"].Value + ";Initial Catalog="
+ Dts.Variables["Saw_Raw_DatabaseName"].Value
+ ";Integrated Security=SSPI;";
using (OleDbConnection conn = new OleDbConnection(excelConnectionString))
{
if (conn.State != ConnectionState.Open)
conn.Open();
using (OleDbCommand oleCmd = new OleDbCommand("select * from [" + Dts.Variables["SheetName"].Value + "$]", conn))
{
using (OleDbDataReader reader = oleCmd.ExecuteReader())
{
InsertData(Dts.Variables["TableName"].Value.ToString(), reader, sqlConnectionString);
}
if (conn.State != ConnectionState.Closed)
conn.Close();
}
}
The exact error is as follows:
'C:\SSIS Packages\TempFiles\Daily Facets Report 8.21.17.xls' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
Any type of help can be very helpful like Code snippet, a link or a suggestion. Thanks in advance friends.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 29-Aug-17 19:48pm.
|
|
|
|
|
|
It is fairly clear that the path in the error message is not the same as either of the locations where that file is actually stored.
I notice also that you are using Extended Properties=Text; to read an Excel workbook. That is not correct, you should use Extended Properties=Excel 8.0; . See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].
|
|
|
|
|
How can i show a pie chart crystal report showing monthly auto sales for all models ( crosswind, d-max, alterra, Mu-X, N-Series, F-Series)?
|
|
|
|
|
|
Hi,
I am starting a process using P/Invoke of
CreateProcessWithTokenW
Eyerthing works fine, e.g. when I run a simple command like "ipconfig > test.log" then the file contains the output of the file. Process Explorer also tells me that the process runs as the user I impersonated to...
When I start a GUI application, however, I run into a strange problem: The process starts without error and the icon of the process pops up in the taskbar (e.g. the notepad icon), but I cannot "look at the GUI". Its a bit hard to explain, but I can click on the taskbar icon and a frame of the Window appears, but is has no "contents". I can click on the close icon and the windows closes.
Please refer to this screenshot. It also shows that this is not a "move to screen" issue
ScreenShot
I'd be happy for all sorts of advice.
Cheers,
Guido
|
|
|
|
|
Without seeing the code you used to call this and setup the parameters you passed in, it's pretty much impossible to tell you what's wrong.
|
|
|
|
|
Hi,
mea culpa.
The code is as follows
public class MyRunAs
{
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool CreateProcessWithTokenW(
IntPtr dupeTokenHandle,
LogonFlags dwLogonFlags,
string applicationName,
string commandLine,
CreationFlags dwCreationFlags,
IntPtr environment,
string currentDirectory,
ref STARTUPINFO sui,
out PROCESS_INFORMATION processInfo);
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool DuplicateTokenEx(IntPtr tokenHandle, int
dwDesiredAccess,
ref SECURITY_ATTRIBUTES lpTokenAttributes, int
SECURITY_IMPERSONATION_LEVEL,
int TOKEN_TYPE, ref IntPtr dupeTokenHandle);
[DllImport("userenv.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool CreateEnvironmentBlock(
ref IntPtr lpEnvironment,
IntPtr hToken,
bool bInherit);
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern bool CreateProcessAsUser(
IntPtr Token,
[MarshalAs(UnmanagedType.LPTStr)] string ApplicationName,
[MarshalAs(UnmanagedType.LPTStr)] string CommandLine,
ref SECURITY_ATTRIBUTES ProcessAttributes,
ref SECURITY_ATTRIBUTES ThreadAttributes,
bool InheritHandles,
CreationFlags dwCreationFlags,
IntPtr Environment,
[MarshalAs(UnmanagedType.LPTStr)] string CurrentDirectory,
ref STARTUPINFO StartupInfo,
out PROCESS_INFORMATION ProcessInformation);
[StructLayout(LayoutKind.Sequential)]
internal struct SECURITY_ATTRIBUTES
{
internal int nLength;
internal int lpSecurityDescriptor;
internal bool bInheritHandle;
}
public enum CreationFlags
{
DefaultErrorMode = 0x04000000,
NewConsole = 0x00000010,
NewProcessGroup = 0x00000200,
SeparateWOWVDM = 0x00000800,
Suspended = 0x00000004,
UnicodeEnvironment = 0x00000400,
ExtendedStartupInfoPresent = 0x00080000
}
public enum LogonFlags
{
WithProfile = 1,
NetCredentialsOnly
}
[StructLayout(LayoutKind.Sequential)]
internal struct STARTUPINFO
{
internal int cb;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpReserved;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpDesktop;
[MarshalAs(UnmanagedType.LPTStr)]
internal string lpTitle;
internal int dwX;
internal int dwY;
internal int dwXSize;
internal int dwYSize;
internal int dwXCountChars;
internal int dwYCountChars;
internal int dwFillAttribute;
internal int dwFlags;
internal short wShowWindow;
internal short cbReserved2;
internal IntPtr lpReserved2;
internal IntPtr hStdInput;
internal IntPtr hStdOutput;
internal IntPtr hStdError;
}
[StructLayout(LayoutKind.Sequential)]
internal struct PROCESS_INFORMATION
{
internal IntPtr hProcess;
internal IntPtr hThread;
internal int dwProcessId;
internal int dwThreadId;
}
const int SecurityAnonymous = 0;
const int SecurityIdentification = 1;
const int SecurityImpersonation = 2;
const int SecurityDelegation = 3;
const int TokenPrimary = 1;
const int TokenImpersonation = 2;
const int LOGON_WITH_PROFILE = 1;
const int LOGON_NETCREDENTIALS_ONLY = 2;
private const int TOKEN_QUERY = 0x0008;
private const int TOKEN_DUPLICATE = 0x0002;
private const int TOKEN_ASSIGN_PRIMARY = 0x0001;
private const int STARTF_USESHOWWINDOW = 0x00000001;
private const int STARTF_FORCEONFEEDBACK = 0x00000040;
private const int CREATE_UNICODE_ENVIRONMENT = 0x00000400;
private const int TOKEN_IMPERSONATE = 0x0004;
private const int TOKEN_QUERY_SOURCE = 0x0010;
private const int TOKEN_ADJUST_PRIVILEGES = 0x0020;
private const int TOKEN_ADJUST_GROUPS = 0x0040;
private const int TOKEN_ADJUST_DEFAULT = 0x0080;
private const int TOKEN_ADJUST_SESSIONID = 0x0100;
private const int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
private const int TOKEN_ALL_ACCESS =
STANDARD_RIGHTS_REQUIRED |
TOKEN_ASSIGN_PRIMARY |
TOKEN_DUPLICATE |
TOKEN_IMPERSONATE |
TOKEN_QUERY |
TOKEN_QUERY_SOURCE |
TOKEN_ADJUST_PRIVILEGES |
TOKEN_ADJUST_GROUPS |
TOKEN_ADJUST_DEFAULT |
TOKEN_ADJUST_SESSIONID;
public static bool CreateTokenChild()
{
try {
STARTUPINFO startInfo = new STARTUPINFO();
startInfo.cb = Marshal.SizeOf(startInfo);
IntPtr dupeTokenHandle = IntPtr.Zero;
WindowsIdentity id = new WindowsIdentity("user@domain");
IntPtr tokenHandle = id.Token;
SECURITY_ATTRIBUTES lpTokenAttributes = new SECURITY_ATTRIBUTES();
lpTokenAttributes.nLength = Marshal.SizeOf(lpTokenAttributes);
bool retVal = DuplicateTokenEx(
tokenHandle,
TOKEN_ALL_ACCESS,
ref lpTokenAttributes,
SecurityImpersonation,
TokenPrimary,
ref dupeTokenHandle);
if (!retVal)
{
int winError = Marshal.GetLastWin32Error();
File.AppendAllText("C:\\tmp\\out.log", DateTime.Now.ToLongTimeString() + " " + winError + Environment.NewLine);
return false;
}
string app = @"c:\Windows\System32\notepad.exe";
string cmd = null;
string spath = @"C:\";
IntPtr env = GetEnvironmentBlock(dupeTokenHandle);
PROCESS_INFORMATION processInfo;
bool ret = CreateProcessWithTokenW(
dupeTokenHandle,
LogonFlags.WithProfile,
app,
cmd,
CreationFlags.UnicodeEnvironment,
env,
spath,
ref startInfo,
out processInfo);
if (!ret)
{
int winError = Marshal.GetLastWin32Error();
File.AppendAllText("C:\\tmp\\out.log", DateTime.Now.ToLongTimeString() + " error: " + winError + Environment.NewLine);
return false;
}
else
{
File.AppendAllText("C:\\tmp\\out.log", DateTime.Now.ToLongTimeString() + " success " + Environment.NewLine);
}
}
catch (Exception e)
{
return false ;
}
finally
{
}
return true;
}
private static IntPtr GetEnvironmentBlock(IntPtr token)
{
var envBlock = IntPtr.Zero;
if (!CreateEnvironmentBlock(ref envBlock, token, false))
{
throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateEnvironmentBlock failed");
}
return envBlock;
}
}
Sorry for that lack of information. I somehow thought, its not code related but rather some security issue. I compared two processes with process explorer and the only thing that I realized was that "normal" processes have security attribute "NT AUTHORITY\INTERACTIVE" which the process I am starting has not ...
I also tried CreateProcessAsUser and it shows exactly the same behavior ...
Cheers and thanks.
Guido
|
|
|
|
|